惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
博客园 - Franky
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
爱范儿
爱范儿
罗磊的独立博客
博客园_首页
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
V
Visual Studio Blog
T
Tailwind CSS Blog

博客园 - Let's DotNet

Generating SSH Keys for Git Keyboard shortcuts for Windows C# 类初始化顺序 - Let's DotNet Office 2007安装后Google拼音输入法莫名其妙消失了,换成了微软拼音 在装有SAP客户端后安装VS2003时出错 Difference between ICallbackEventHandler and AJAX 无法通过Project Professional 2003连接到Project Server 2003的解决办法(转) AutoCoder——全新自动代码框架 基于性能的编程技巧点滴 Atlas Project (转) DB2编程技巧 动态添加控件的一个注意点 SQL Server 高阶应用 限制多行文本框(TextArea)中输入文字的长度(转) 给自己的某个文件夹的文件做一个列表(转) Google 桌面搜索... Eclipse 3.0资料收集(转) 一种改进的轻量级.NET应用程序性能测试框架 ASP.NET 应用程序性能优化
"Union" in Oracle - Let's DotNet
Let's DotNet · 2005-09-23 · via 博客园 - Let's DotNet
 

 Today, I have found a funny problem when use "Union" in Oracle.
 Just like this,

 I have two tables, one calls "TB_STUDENT" and the other "TB_RESOURCE"

TB_STUDENT
{
    WORKER_ID NVARCHAR2(40),
    SEX INTEGER
}

TB_RESOURCE
{
    RESOURCE_ID NVARCHAR2(40),
     ...
}

for the two tables, "TB_STUDENT" has some records while "TB_RESOURCE" has no record!

then, I try the following SQL sentence:

SELECT WORKER_ID FROM TB_STUDENT
UNION
SELECT '' FROM TB_RESOURCE

it got an error "ORA-12704: 字符集不匹配";

I thought maybe it was caused by '', because '' (empty string) denotes the NULL value in Oracle.
So, changed it to ' ';

Unfortunately, it still didn't work!

...

oh, maybe it requires strictly type check!

SELECT WORKER_ID FROM TB_STUDENT
UNION
SELECT CAST('' AS NVARCHAR2(40)) FROM TB_RESOURCE

ok,run passed!

// new added, 05-09-27
oftenly, we think it would be "OK" when using Parameter.
for instance,
 
SELECT LMS_TEACHER.TEACHER_ID FROM LMS_TEACHER WHERE LMS_TEACHER.CODE='I0001' AND LMS_TEACHER.TEACHER_ID<>'';

I use this sentence to find whether there exist a record with "LMS_TEACHER.CODE='I0001'", because LMS_TEACHER.TEACHER_ID is a primary key, so there is no record accord with the condition "LMS_TEACHER.TEACHER_ID<>''". And in the program, I use a sentence with parameter instead the front sentence, just like:

SELECT LMS_TEACHER.TEACHER_ID FROM LMS_TEACHER WHERE LMS_TEACHER.CODE=@NewCode AND LMS_TEACHER.TEACHER_ID<>@TeacherID;

Unfortunately, it returns no record when there is a record with LMS_TEACHER.CODE='I0001' ;
Then I change [<>''] to [IS NOT NULL], it runs ok.

the same result appeared when I try the following setences:
SELECT * FROM LMS_TEACHER WHERE LMS_TEACHER.TEACHER_ID<>' '; (ok)
SELECT * FROM LMS_TEACHER WHERE LMS_TEACHER.TEACHER_ID<>'';  (no record)
SELECT * FROM LMS_TEACHER WHERE LMS_TEACHER.TEACHER_ID IS NOT NULL; (ok)

[ :( it scratches my head over ]