CALL¶
Calls a stored procedure.
- See also:
Syntax¶
Required parameters¶
procedure_name ( [ [ arg_name => ] arg , ... ] )Specifies the identifier (
procedure_name) for the procedure to call and any input arguments.You can either specify the input arguments by name (
arg_name => arg) or by position (arg).Note the following:
You must either specify all arguments by name or by position. You can’t specify some of the arguments by name and other arguments by position.
When specifying an argument by name, you can’t use double quotes around the argument name.
If two functions or two procedures have the same name but different argument types, you can use the argument names to specify which function or procedure to execute, if the argument names are different. Refer to Overloading procedures and functions.
Optional parameters¶
INTO :snowflake_scripting_variableSets the specified Snowflake Scripting variable to the return value of the stored procedure.
Examples¶
For more extensive examples of creating and calling stored procedures, see Working with stored procedures.
Each argument to a stored procedure can be a general expression:
An argument can be a subquery:
You can call only one stored procedure per CALL statement. For example, the following statement fails:
Also, you cannot use a stored procedure CALL as part of an expression. For example, all the following statements fail:
However, inside a stored procedure, the stored procedure can call another stored procedure, or call itself recursively.
Caution
Nested calls can exceed the maximum allowed stack depth, so be careful when nesting calls, especially when using recursion.
The following example calls a stored procedure named sv_proc1 and passes in a string literal and number as input arguments.
The example specifies the arguments by position:
You can also specify the arguments by their names:
The following example demonstrates how to set and pass a session variable as an input argument to a stored procedure:
The following is an example of a Snowflake Scripting block that captures the return value of a stored procedure in a Snowflake Scripting variable.
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_stream or execute_string method in Python Connector
code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):