加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql与Oracle:空字符串与null

发布时间:2020-12-13 16:53:56 所属栏目:百科 来源:网络整理
导读:空字符串:两个单引号,中间无空格等任何内容在postgresql中,空字符串与null是不同的;而oracle中,空字符串与null等同。测试如下:postgresql中:postgres=# insert into testnull values(1,'feikong');INSERT 0 1postgres=# insert into testnull values(
空字符串:两个单引号,中间无空格等任何内容

在postgresql中,空字符串与null是不同的;而oracle中,空字符串与null等同。测试如下:

postgresql中:
postgres=# insert into testnull values(1,'feikong');
INSERT 0 1
postgres=# insert into testnull values(2,null);
INSERT 0 1
postgres=# insert into testnull values(3,'');
INSERT 0 1
postgres=#  select * from testnull;
 id |  name   
----+---------
  1 | feikong
  2 |
  3 |
(3 rows)

postgres=# select * from testnull where name is null;     ---只有2为null
 id | name
----+------
  2 |
(1 row)

postgres=# select * from testnull where name is  not null;
 id |  name   
----+---------
  1 | feikong
  3 |
(2 rows)


Oracle中:
SQL> insert into testnull values(1,'feikong');

1 row inserted

SQL> insert into testnull values(2,null);

1 row inserted

SQL> insert into testnull values(3,'');

1 row inserted

SQL> commit;

Commit complete

SQL> select * from testnull;

        ID NAME
---------- ----------
         1 feikong
         2
         3

SQL> select * from testnull where name is null;   --2,3为null

        ID NAME
---------- ----------
         2
         3

SQL> select * from testnull where name is  not null;

        ID NAME
---------- ----------
         1 feikong

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读