CALL
The CALL statement is used to call a procedure in SQL Script.
Syntax
CALL <procedureName> ( [<valueExpression>[,…]] )]
The <procedureName> refers to the name of a procedure declared using the syntax for a procedure declaration. See
SQL Script Procedure Header for procedure declaration.
Parentheses in the CALL syntax are not required if there are no parameters.
Remarks
• IN parameters can be passed any value expression. For details, see
Value Expressions. The expression is implicitly cast, if required, to match the type of the IN parameter. IN parameters can be literals, expressions, or variables. If an IN parameter is a variable, the value is not altered. IN parameters with the PIPE modifier (
PIPE Modifier) can only pass in variables that are also PIPE variables. This means only IN or OUT parameters of the current procedure that have the PIPE modifier can be passed in.
• The expressions being passed to IN parameters are evaluated from left to right.
• INOUT and OUT parameters must be passed a variable of the appropriate type. No implicit type conversion is supported. For INOUT parameters, the value is not altered if it is not changed in the procedure. For OUT parameters, the value is set to NULL if not altered in the procedure. OUT parameters with the PIPE modifier can only be passed a cursor variable with the same cursor type as the PIPE.
Examples
PROCEDURE square (IN x INTEGER, OUT result INTEGER)
BEGIN
SET result = x * x;
END
PROCEDURE p( )
BEGIN
DECLARE y INTEGER;
CALL square(2, y);
-- y is 4
CALL sqaure(y, y);
-- y is 16
END
PROCEDURE factorial (IN x INTEGER, OUT result INTEGER)
BEGIN
IF x = 1 THEN
SET result = 1;
ELSE
CALL /shared/factorial(x-1; result);
SET result = x * result;
END