EXECUTE Statement

Executes the script called script-name, which may be enclosed in quotes if the script name contains spaces or special characters. If a result-variable is specified, then that variable will receive the scalar value, if any, returned from the script. The result-variable does not need to be declared beforehand; the EXECUTE statement itself will declare the variable if it does not exist. If the script does not call RETURN, then the return value is NULL.

A script may define its own input parameters using the DECLARE PARAMETER statement. If parameters are present in the script, then any EXECUTE statement that calls it must provide argument values for those parameters. The exception is if the DECLARE PARAMETER statement includes a default value. If so, then the EXECUTE statement may omit that parameter, or it may use the special keyword DEFAULT; in both cases, the default value defined by the DECLARE PARAMETER statement is used.

Syntax


Parameters

Example

-- Executes the script named "Script2" using default
-- values for all parameters and ignoring the return value.
EXECUTE Script2;

-- Executes the script named "Script2" and stores the
-- return value in the variable @returnValue.
EXECUTE @returnValue = Script2;

-- Executes the script named "My Script", using quotes
-- because the name contains whitespace. EXECUTE 'My Script';

-- Executes the script named "Script2" and passes two
-- argument values. @foo and @bar refer to parameters
-- defined using DECLARE PARAMETER inside "Script2".
EXECUTE Script2 @foo = 1, @bar = 2;