NULL Value and NULL String in DB2

Source: Internet
Author: User

I always thought that a NULL string is NULL. When I inserted a NULL String, I could use NULL. However, some time ago, I found that the NULL Character Set was not included after I used the not in value, at that time, I also thought that it should be included. Then I did the following test and found that NULL and NULL strings in DB2 are not the same thing.

Create table tab
(Id integer not null,
Name char (50 ),
Empid char (10 ),
Salary char (15)
);

Insert into tab values (1, 'jack', '123', '123 ');

Insert into tab values (2, 'Tom ', '123 ','');

Insert into tab values (3, 'Lucy ', '20160301', '20160301 ');

Insert into tab values (4, 'jame', '2013 ','');

Insert into tab values (4, 'Kim ', '20140901', null );


Db2 => select * from tab;
Select * from tab

ID NAME EMPID SALARY
--------------------------------------------------------------------------------------
1 JACK 0001 2000
Two TOM 0002
3 LUCY 0003 3000
4. JAME 0004
4. KIM 0005-

5 record (s) selected.

Db2 => select * from tab where salary not in ('20140901', '20160901 ');
Select * from tab where salary not in ('20140901', '20160901 ')

ID NAME EMPID SALARY
--------------------------------------------------------------------------------------
Two TOM 0002
4. JAME 0004

2 record (s) selected.

Db2 => select * from tab where salary is null;
Select * from tab where salary is null

ID NAME EMPID SALARY
--------------------------------------------------------------------------------------
4. KIM 0005-

1 record (s) selected
The answer to this DB2 document is that NULL is an uncertain value and can represent any value. Therefore, it is not included in any specified set and the NULL value cannot be filtered by column values, it can only be filtered by the is null or is not null method, so you can see the result above. This seems to be different from Oracle, so different databases are still different and cannot be applied directly, perform more hands-on tests to learn the truth.

Recommended reading:

DB2 database performance adjustment and optimization (1st and 2) PDF

DB2 database performance optimization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.