What is the correct way to check for null values ​​in PL / SQL?

IF purpose = null THEN
   v_purpose := '';
ELSE
   v_purpose := ' for ' || purpose;
END IF;

When the target is null, it still goes to else ... why ?!

+3
source share
3 answers

Correct test

IF purpose IS NULL THEN

This is because it is NULLnot a value stored in a field. This is an attribute about a field stored elsewhere (but inside the string).

Setting the field on NULLdoes not appear to be a common purpose, so it seems to be perfectly orthogonal to expect testing for it by direct comparison. However, in order for it to work as I understand it, the SQL assignment primitive has a magic hidden aspect that distracts the purpose of the special character NULLfrom setting the attribute, not the field.

+5
source

NULL - SQL, . IS IS NOT , NULL.

. :

. Null In Oracle - . , . NULL . NULL , . , NULL , "0".

+5

purpose = null , , purpose (. @Paul Sasik ). , , IF ELSE.

+1

All Articles