PL/SQL NULL Statement
PL/SQL, the Procedural Language/Structured Query Language, is a database programming language utilized for database management in Oracle. Within this language, the NULL statement is crucial in enhancing code readability and functionality.
This article aims to look into the significance of the NULL statement in PL/SQL, exploring its various applications and benefits.
NULL Statement in PL/SQL
The NULL statement in PL/SQL is a construct or feature representing a no-operation or empty statement. It is used when a statement is syntactically necessary, but no action must be performed on it. Essentially, it signifies the placeholder where no code execution occurs. The NULL statement works like a stand-in within PL/SQL code.
The syntax needs it but doesn't do any particular job. It shows that no specific code has to run at that moment. The NULL statement becomes particularly valuable when creating placeholders or in scenarios requiring a mandatory statement to fulfill syntactic requirements. By acting as a marker where no action is required, it informs future developers that this part of the code doesn't need processing at that time, keeping the code simple and clean.
Syntax of PL/SQL Null Statement
The basic syntax of the NULL statement in PL/SQL is very simple. It's just the keyword NULL followed by a semicolon (;).
-- Some PL/SQL code executing other statements -- The NULL statement used as a placeholder NULL; -- More PL/SQL code END;
Using PL/SQL NULL Statement to Improve Code Readability
The NULL statement proves particularly useful in enhancing code readability and usability. Consider a scenario where a placeholder is required within a block of code, but no specific action is needed to take place:
BEGIN -- Perform certain operations NULL; -- Null statement as a placeholder -- Continue with other operations END;
By employing the NULL statement in such instances, developers can clearly denote sections in the code that require no action, making the code more understandable and readable for other programmers or during future reviews and modifications.
Placeholders in Subprograms with the NULL Statement
Another significant application of the NULL statement is creating placeholders within subprograms. For instance, when defining a procedure or function body, placeholders might be needed:
CREATE OR REPLACE PROCEDURE myProcedure AS BEGIN -- Perform some tasks NULL; -- Placeholder for future functionality -- Continue with more tasks END;
In this case, the Null statement serves as a placeholder for potential future modifications or additions to the subprogram's logic, allowing developers to structure code architecture more effectively.
Using PL/SQL NULL Statement as a Target for GOTO Statement
The NULL statement can also act as a target for a GOTO statement, aiding in controlling program flow:
DECLARE x INT := 3; BEGIN IF x > 5 THEN DBMS_OUTPUT.PUT_LINE('x is greater than 5'); ELSE NULL; -- The NULL statement does nothing in the ELSE block END IF; END;
By utilizing the NULL statement as a target for GOTO in the above code can navigate program execution to a designated placeholder within the code very easily.
Explanation:
- We set a variable 'x' to the value 3. The IF statement checks if 'x' is bigger than 5. But, since 'x' is not greater than 5 (it's 3, not more than 5), the condition in the IF statement is not true.
- When this happens, the program goes into the ELSE part. Inside that part, there's a statement that does nothing, called NULL. It's there just because the IF-ELSE needs something inside the ELSE part.
- So, when 'x' is not greater than 5, the program sees the NULL inside the ELSE part, and it keeps going to the end of the PL/SQL part without doing anything special in the ELSE part.
Output:

NULL in Exception Handling
In Oracle PL/SQL, a NULL statement can act as a placeholder for the program , indicating that no particular action is needed to perform. When incorporated into exception handling, this NULL statement within the EXCEPTION block signifies that no specific action is required to address a certain error situation.
BEGIN -- Some operations or code execution -- Exception handling block BEGIN -- Code that might raise an exception DECLARE numerator INT := 10; denominator INT := 0; result INT; BEGIN result := numerator / denominator; -- This line may raise a division by zero exception EXCEPTION WHEN ZERO_DIVIDE THEN -- NULL statement used as a placeholder for no specific action needed NULL; -- Placeholder: No action required for this specific condition END; END; END;
Explanation:
- Within the catch part, the code tries dividing a number where the bottom bit is put to zero, which might cause a ZERO_DIVIDE error.
- In case of a ZERO_DIVIDE error, the EXCEPTION WHEN ZERO_DIVIDE THEN part catches it.
- Instead of doing anything particular for this issue, the NULL thing is used as a placeholder, showing that nothing needs to be done or planned for this specific error.
Output:

Important Points About PL/SQL NULL Statement
- Unlike many conditional or placeholder operations, a NULL statement has virtually no impact on performance, as Oracle doesn’t allocate additional processing time to it.
- Instead of using complex conditions to skip specific loop iterations, a NULL statement inside an IF condition can simplify the logic without altering loop performance.
- Leaving code blocks empty can lead to confusion for future developers. By using NULL, developers signal that the block is intentionally left inactive, helping avoid misunderstandings and enhancing readability.
- While COMMENT tags are useful, placing NULL in a block often serves as a more effective placeholder, especially when indicating that a block has intentionally no action.