Skip to content

NULL

NULL is a statement that can be used as a 'NoOps' (no operation) statement.

The NULL statement is only valid within a scripting block.

Syntax

sql
NULL;

Usage Notes

  • If no higher-level handler is present, a NULL statement can be used inside an exception handler to ensure that code execution continues and does not abort.
  • A NULL statement has no effect in a conditional branch but explicitly signals to the reader that this branch was intentionally handled and not accidentally omitted.
  • The NULL statement should be used sparingly.
  • If every code path in a stored procedure with an exception handler is expected to return a value, it is recommended to return an explicit NULL value or an error indicator instead of using a NULL statement.

Example

In this case, a NULL statement is used inside an exception handler to ensure that the exception is caught (and not propagated to the caller) and that no specific action is taken. However, in this case, the NULL value returned by the CALL statement is not directly caused by the NULL statement in the exception handler. Instead, NULL is returned because the stored procedure did not execute an explicit RETURN statement. Due to this ambiguity, it is recommended to return an explicit value from every branch in the exception handler instead of using a NULL statement.

sql
CREATE PROCEDURE mkw_doku.null_statement_exception
RETURNS STRING
AS
BEGIN
    SELECT 1 / 0;
    RETURN 'Dividing by 0 is not allowed!';
END;

CALL mkw_doku.null_statement_exception;
Error: divisor is equal to zero
 at mkw_doku.null_statement_exception (5:5)
 at mkw_doku.test_abfragen (9:1)
sql
CREATE PROCEDURE mkw_doku.null_statement_pass_thru
RETURNS STRING
AS
BEGIN
    SELECT 1 / 0;
    RETURN 'Dividing by 0 is not allowed!';
EXCEPTION
    WHEN OTHER THEN
        NULL;
END;

CALL mkw_doku.null_statement_pass_thru;
Procedure 'mkw_doku.null_statement_pass_thru' was successfully executed