oracle数据库字符串添加空格,空字符串和空格字符串在informix和oralce 的差异

空字符串和空格字符串在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。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值