The NULL Statement
Usually when you write a statement in a program, you want it to do something. There are cases, however, when you want to tell PL/SQL to do absolutely nothing, and that is where the NULL statement comes in handy. The NULL statement has the following format:
NULL;
Well, you wouldn’t want ado-nothing statement to be complicated, would you? The NULL statement is simply the reserved word NULL followed by a semicolon (;) to indicate that this is a statement and not a NULL value. The NULL statement does nothing except pass control to the next executable statement.
Why would you want to use the NULL statement? There are several reasons, described in the following sections.
Improving Program Readability
There are many situations in your program where you logically do not want to take any action. In most of these cases, PL/SQL will let you write nothing and the program will execute as you wish. The only drawback is the ambiguity surrounding this solution: it is not clear to a person examining the program that you purposely took no action.
For example, when you write an IF statement, you do not have to include an ELSE clause. To produce a report based on a selection, you can code:
IF :report.selection = 'DETAIL' THEN exec_detail_report; END IF;
What should the program be doing if the report selection is not `DETAIL'? One would assume that the program is supposed to do nothing. But because this is not explicitly stated in the code, one is left to wonder if perhaps there was ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access