DB2 10.5 for Linux, UNIX, and Windows

CALL statement

The CALL statement calls a procedure or a foreign procedure.

Invocation

This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared.

When invoked using the command line processor, there are some additional rules for specifying arguments of the procedure.

For more information, refer to Using command line SQL statements and XQuery statements.

Authorization

The privileges held by the authorization ID of the statement must include at least one of the following authorities:
  • EXECUTE privilege on the procedure
  • DATAACCESS authority

If a matching procedure exists that the authorization ID of the statement is not authorized to execute, an error is returned (SQLSTATE 42501).

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CALL--procedure-name--+----------------------------+--------><
                         |    .-,----------------.    |   
                         |    V                  |    |   
                         '-(------| argument |---+--)-'   

argument

|--+--------------------+--+-expression-+-----------------------|
   '-parameter-name--=>-'  +-DEFAULT----+   
                           '-NULL-------'   

Description

procedure-name
Specifies the procedure that is to be called. It must be a procedure that is described in the catalog or that is declared in the scope of the compound SQL (compiled) statement that includes the CALL statement. The specific procedure to invoke is chosen using procedure resolution. (For more details, see the "Notes" section of this statement.)
argument
parameter-name
Name of the parameter to which the argument is assigned. When an argument is assigned to a parameter by name, then all the arguments that follow it must also be assigned by name (SQLSTATE 4274K).

A named argument must be specified only once (implicitly or explicitly) (SQLSTATE 4274K).

Named arguments are not supported on the call to an uncataloged procedure (SQLSTATE 4274K).

expression or DEFAULT or NULL
Each specification of expression, the DEFAULT keyword, or the NULL keyword is an argument of the CALL. The nth unnamed argument of the CALL statement corresponds to the nth parameter defined in the CREATE PROCEDURE statement for the procedure.

Named arguments correspond to the same named parameter, regardless of the order in which they are specified.

If the DEFAULT keyword is specified, the default as defined in the CREATE PROCEDURE statement is used if it exists; otherwise the null value is used as the default.

If the NULL keyword is specified, the null value is passed as the parameter value.

Each argument of the CALL must be compatible with the corresponding parameter in the procedure definition as follows:
  • IN parameter
    • The argument must be assignable to the parameter.
    • The assignment of a string argument uses the storage assignment rules.
  • OUT parameter
    • The argument must be a single variable or parameter marker (SQLSTATE 42886).
    • The argument must be assignable to the parameter.
    • The assignment of a string argument uses the retrieval assignment rules.
  • INOUT parameter
    • The argument must be a single variable or parameter marker (SQLSTATE 42886).
    • The argument must be assignable to the parameter.
    • The assignment of a string argument uses the storage assignment rules on invocation and the retrieval assignment rules on return.

Notes

Examples