ITPub博客

首页 > 数据库 > 数据库开发技术 > 空字符串和空格字符串在informix和oralce 的差异

空字符串和空格字符串在informix和oralce 的差异

原创 数据库开发技术 作者:liahtobjtosh 时间:2009-10-09 16:43:46 0 删除 编辑
空字符串和空格字符串在informix和oralce 的差异[@more@]

informix:操作如下:
> CREATE TABLE tt ( c1 int,c2 VARCHAR(8),UNIQUE (c1,c2) CONSTRAINT u_tt );

Table created.

> insert into tt(c1,c2) values(1,' '); -- 两个空格,' '被解释为''

1 row(s) inserted.

> insert into tt(c1,c2) values(1,' '); --一个空格,' '被解释为'',所以出错

268: Unique constraint (informix.u_tt) violated.

100: ISAM error: duplicate value for a record with unique key.
Error in line 1
Near character position 33
> insert into tt(c1) values(2);

1 row(s) inserted.

> select * from tt;


c1 c2

1
2

2 row(s) retrieved.

> select * from tt where c2 ='';


c1 c2

1

1 row(s) retrieved.

> select * from tt where c2 = ' '; --一个空格' '被解释为''


c1 c2

1

1 row(s) retrieved.

> select * from tt where c2 = ' '; --二个空格' '被解释为''


c1 c2

1

1 row(s) retrieved.

> select * from tt where c2 is null;


c1 c2

2

1 row(s) retrieved.

> select c1,length(c2) from tt;


c1 (expression)

1 0
2

2 row(s) retrieved.

>
可见informix 把 '' 与 ' ' 与 ' ' 是同等对待,将其看成''


oracle:

操作如下:

SQL> CREATE TABLE tt ( c1 int,c2 VARCHAR(8), CONSTRAINT u_tt UNIQUE (c1,c2));

表已创建。

SQL> insert into tt(c1,c2) values(1,' ');--两个空格

已创建 1 行。

SQL> insert into tt(c1,c2) values(1,''); --没有空格

已创建 1 行。

SQL> insert into tt(c1) values(2); --c2被填充为null

已创建 1 行。

SQL> select * from tt;

C1 C2
---------- ----------------
1
1
2

SQL> select c1,nvl(c2,'null') from tt;-- 可见,''被解释成null

C1 NVL(C2,'NULL')
---------- ----------------
1
1 null
2 null

SQL> select * from tt where c2 =''; --因为表中的''被解释成null,所以没有查到

未选定行

SQL> select * from tt where c2 is null;

C1 C2
---------- ----------------
1
2

SQL> select * from tt where c2 = ' ';

C1 C2
---------- ----------------
1

SQL>

从上可见。ORACLE把''解释成 NULL。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22565551/viewspace-1027676/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-09-19

  • 博文量
    48
  • 访问量
    249175