加补一条,曾经我遇到过这样的一个问题,从sql server转移数据库到oracle时发生的(用透明网关直接全部梭哈的那种数据转移),sql server的空(NULL)转到oracle后,在oracle数据库里面NULL变为空字符(asc码为0的那个字符)。此时在oracle内查询为空字符,不能复制粘贴,不能用 is null判断,要筛选此类数据可用函数ascii(字段名)=0
加补一条,曾经我遇到过这样的一个问题,从sql server转移数据库到oracle时发生的(用透明网关直接全部梭哈的那种数据转移),sql server的空(NULL)转到oracle后,在oracle数据库里面NULL变为空字符(asc码为0的那个字符)。此时在oracle内查询为空字符,不能复制粘贴,不能用 is null判断,要筛选此类数据可用函数ascii(字段名)=0oracle里面的空字符串''和空NULL是等价的,条件中可以写='',也可以写is null,很多数据库这两者不一样并不是等价的哦,空字符串的ascii码是0,但是null的ascii码还是null,由此通过asc码就可以看出空字符串和null是两个看起来长得一样的数据,但实际上是不一样的数据,且空字符串插入到oracle一般是存入的null而不是空字符串,输入法没办法打出来,我那次偶遇到这种空字符串数据是因为sql server转oracle时透明网关的问题,将null转成空字符串插入到oracle的表字段中,我试过多次,无法用=''或者is null判断,但可以用ascii(字段名)=0来查询出
SQL> drop table test purge;Table dropped.SQL> create table test( x varchar2(10));Table created.SQL> insert into test values(null);1 row created.SQL> insert into test values('');1 row created.SQL> commit;Commit complete.SQL> select * from test;X ----------SQL> select count(*) from test; COUNT(*) ---------- 2SQL> select count(*) from test where x is null; COUNT(*) ---------- 2SQL> select count(*) from test where x=''; COUNT(*) ---------- 0SQL> select dump(x) from test;DUMP(X) -------------------------------------------------------------------------------- NULL NULLSQL> insert into test values('111');1 row created.SQL> update test set x='' where x='111';1 row updated.SQL> commit;Commit complete.SQL> select dump(x) from test;DUMP(X) -------------------------------------------------------------------------------- NULL NULL NULLSQL> 我上面说的确实有点问题:where条件里的x=''这种写法和is null不等价。 不过insert和update的时候使用''空字符串即代表null
比如工作流中的审批流程,最好不要用审批意见是否为NULL判断具体的节点,而是用具体的字段判断。
----------SQL> select count(*) from test; COUNT(*)
----------
2SQL> select count(*) from test where x is null; COUNT(*)
----------
2SQL> select count(*) from test where x=''; COUNT(*)
----------
0SQL> select dump(x) from test;DUMP(X)
--------------------------------------------------------------------------------
NULL
NULLSQL> insert into test values('111');1 row created.SQL> update test set x='' where x='111';1 row updated.SQL> commit;Commit complete.SQL> select dump(x) from test;DUMP(X)
--------------------------------------------------------------------------------
NULL
NULL
NULLSQL> 我上面说的确实有点问题:where条件里的x=''这种写法和is null不等价。
不过insert和update的时候使用''空字符串即代表null