NULL (Snowflake Scripting) | Snowflake Documentation (original) (raw)

ReferenceScripting referenceNULL

NULL can be used as a “no-op” (no operation) statement.

Syntax

Usage notes

Example

The following code uses a NULL statement in an exception handler to ensure that the exception is caught (rather than passed up to the caller), but no specific action is taken:

CREATE PROCEDURE null_as_statement() RETURNS VARCHAR LANGUAGE SQL AS BEGINSELECT1/0;RETURN′Ifyouseethis,theexceptionwasnotthrown/caughtproperly.′;EXCEPTIONWHENOTHERTHENNULL;END;BEGIN SELECT 1 / 0; RETURN 'If you see this, the exception was not thrown/caught properly.'; EXCEPTION WHEN OTHER THEN NULL; END;BEGINSELECT1/0;RETURNIfyouseethis,theexceptionwasnotthrown/caughtproperly.;EXCEPTIONWHENOTHERTHENNULL;END; ;

CALL null_as_statement(); +-------------------+

NULL_AS_STATEMENT
NULL
+-------------------+

Note

The NULL value returned by the CALL statement is not directly due to the NULL statement in the exception; instead, the return value is NULL because the stored procedure did not execute an explicit RETURN statement.

Snowflake recommends that stored procedures explicitly return a value, including in each branch of the exception handler.