SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Use NULL as Conditions?

Go down

How To Use NULL as Conditions? Empty How To Use NULL as Conditions?

Post by Micheal Sat Jan 16, 2010 9:21 pm

If you want to compare values against NULL as conditions, you should use the "IS NULL" or "IS
NOT NULL" operator. Do not use "=" or "<>" against NULL. The sample script below shows you
some good examples:
SELECT 'A' IS NULL FROM DUAL;
-- Error: Boolean is not data type.
-- Boolean can only be used as conditions
SELECT CASE WHEN 'A' IS NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
FALSE
SELECT CASE WHEN '' IS NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
TRUE
SELECT CASE WHEN 0 IS NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
FALSE
SELECT CASE WHEN NULL IS NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
TRUE
SELECT CASE WHEN 'A' = NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
-- Do not use "="
FALSE
SELECT CASE WHEN 'A' <> NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
-- Do not use "<>"
FALSE
SELECT CASE WHEN NULL = NULL THEN 'TRUE' ELSE 'FALSE' END FROM DUAL;
-- Do not use "="
FALSE
How To Concatenate Two Text Values?
There are two ways to concatenate two text values together:
CONCAT() function.
'||' operation.
Here is some examples on how to use them:
SELECT 'FYI' || 'Center' || '.com' FROM DUAL;
FYICenter.com
SELECT CONCAT('FYICenter','.com') FROM DUAL;
FYICenter.com

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum