If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > NULL value check in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-10, 02:43
ssaiju ssaiju is offline
Registered User
 
Join Date: Dec 2010
Posts: 4
Question NULL value check in DB2

Hi,

I have a requirement to check whether IS [NOT] NULL function like anything in DB2, to check whether it is NULL

in oracle we can use
SELECT a FROM abc
WHERE IS NOT NULL

is there any thing similar in DB2 which can be used in a WHERE clause
please help

Saiju
Reply With Quote
  #2 (permalink)  
Old 12-14-10, 05:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by ssaiju View Post
is there any thing similar in DB2 which can be used in a WHERE clause
yes, you can do the same in DB2

however, your oracle example is not quite right --
Quote:
SELECT a FROM abc
WHERE IS NOT NULL
this is incorrect in any database system

it should be like this --
Code:
SELECT a FROM abc 
WHERE something IS NOT NULL
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-14-10, 06:06
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
My tutor once said: "think of that little river in austria: the INN" when I coded someting like "not is null" which was rejected as valid SQL
Reply With Quote
  #4 (permalink)  
Old 12-14-10, 06:13
ssaiju ssaiju is offline
Registered User
 
Join Date: Dec 2010
Posts: 4
Question

thanks for the reply & correction

SELECT a FROM abc
WHERE smething IS NOT NULL


is fetching NULL values as well in 9.7.

Is there any specific setting needs to be done ..?
Reply With Quote
  #5 (permalink)  
Old 12-14-10, 06:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what is the exact query you ran, please?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 12-14-10, 08:02
ssaiju ssaiju is offline
Registered User
 
Join Date: Dec 2010
Posts: 4
Question

The below query returns null values in DB2 9.7

select NEG_INSTR_SER_NO from journl_entry_item where NEG_INSTR_SER_NO is not null

Any other alternative to check null values ..?
Reply With Quote
  #7 (permalink)  
Old 12-14-10, 08:25
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Are you confusing empty strings with nulls, may be?
Reply With Quote
  #8 (permalink)  
Old 12-14-10, 08:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by n_i View Post
Are you confusing empty strings with nulls, may be?
not his fault, really, coming from oracle which doesn't know the difference
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 12-14-10, 08:37
ssaiju ssaiju is offline
Registered User
 
Join Date: Dec 2010
Posts: 4
Question

the same dataset behaves differently in oracle and DB2 for the same query ..
i am just trying to find the difference in implementation

How the DB2 differentiate an empty string compared to oracle ..?
Reply With Quote
  #10 (permalink)  
Old 12-14-10, 09:31
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
an empty string (null string/string with length zero) is = '' (or = "")

null is a column attribute. a column may contain a
'null string/empty string/varchar length 0/fixed length all spaces'
but if a column is null, then there is no value/data to check, you check the attribute,
which in db2 is IS COLUMN NULL.
__________________
Dick Brenholtz, Ami in Deutschland
Reply With Quote
  #11 (permalink)  
Old 12-14-10, 10:20
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
do you mean you loaded data from a file into a DB2 table and you are now trying to find records that are not null and you are finding records that should be null? If that is the case, then you should look at your load control statement to see if the null indicator value was identified for the load process.
Dave
Reply With Quote
  #12 (permalink)  
Old 12-14-10, 11:50
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
In Oracle, testing = '' (two single quotes) is the same as testing for null. This is not in accordance with ANSI SQL standards and is not supported by normal DB2 syntax, however, I am not sure about Oracle compatibility mode in DB2 9.7.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Tags
db2, null

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On