How to use PL/SQL NULL Statement to Provide a Target for a GOTO In SQL
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:
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 plays a crucial role in enhancing code readability and functionality. This article aims to delve into the significance of the Null statement in PL/SQL, exploring its various applications and benefits.
Contact Us