|
Home >> FAQs/Tutorials >> Oracle DBA FAQ >> Index
Oracle DBA FAQ - Understanding PL/SQL Language Basics
By: FYIcenter.com
Part:
1
2
3
4
5
(Continued from previous part...)
What Is NULL in PL/SQL?
NULL is a reserved key word and it stands for two things in PL/SQL:
- NULL is an executable statement, and means doing nothing.
- NULL is a data balue, and means no value.
The following sample script shows you examples of using NULL keyword:
DECLARE
next_task CHAR(80);
BEGIN
next_task := NULL; -- NULL value
IF next_task IS NOT NULL THEN
DBMS_OUTPUT.PUT_LINE('I am busy.');
ELSE
DBMS_OUTPUT.PUT_LINE('I am free.');
END IF;
IF next_task IS NULL THEN
NULL; -- NULL statement
ELSE
DBMS_OUTPUT.PUT_LINE('... working on ' || next_task);
END IF;
END;
This script should print this:
I am free.
How To Test NULL Values?
There ate two special comparison operators you can use on NULL values:
- "variable IS NULL" - Returns TRUE if the variable value is NULL.
- "variable IS NOT NULL" - Return TRUE if the variable value is not NULL.
The following sample script shows you examples of comparing NULL values:
DECLARE
next_task CHAR(80);
BEGIN
next_task := NULL;
IF next_task IS NOT NULL THEN
DBMS_OUTPUT.PUT_LINE('I am busy.');
ELSE
DBMS_OUTPUT.PUT_LINE('I am free.');
END IF;
IF next_task IS NULL THEN
NULL;
ELSE
DBMS_OUTPUT.PUT_LINE('... working on ' || next_task);
END IF;
END;
Note that "variable = NULL" is not a valid operation. This script should print this:
I am free.
Part:
1
2
3
4
5
|