IBM Books

Call Level Interface Guide and Reference

Calling Stored Procedures

Stored procedures are invoked from a DB2 CLI application by passing the following CALL statement syntax to SQLExecDirect() or to SQLPrepare() followed by SQLExecute().

                            +-,------+
                            V        |
>>-CALL--procedure-name--(----+----+-+--)----------------------><
                              +-?--+
 
Note:

Although the CALL statement cannot be prepared dynamically, DB2 CLI accepts the CALL statement as if it could be dynamically prepared.

Stored procedures can also be called using the ODBC vendor escape sequence shown in "Stored Procedure Call Syntax".

procedure-name
Specifies a stored procedure name, and it can take one of the following forms:

For more information regarding the use of the CALL statement and stored procedures, refer to the SQL Reference and the Embedded SQL Programming Guide.

If the server is DB2 Universal Database Version 2.1 or later, or DB2 for MVS/ESA V4.1 or later, SQLProcedures() can be called to obtain a list of stored procedures available at the database.
Note:For DB2 Universal Database, SQLProcedures() may not return all procedures, and applications can use any valid procedure, regardless of whether it is returned by SQLProcedures(). For more information, refer to "Registering Stored Procedures" and SQLProcedures - Get List of Procedure Names.

The ? in the CALL statement syntax diagram denote parameter markers corresponding to the arguments for a stored procedure. All arguments must be passed using parameter markers; literals, the NULL keyword, and special registers are not allowed. However, literals can be used if the vendor escape call statement is used, ie. the call statement is surrounded by curly braces '{...}'.

The parameter markers in the CALL statement are bound to application variables using SQLBindParameter(). Although stored procedure arguments can be used both for input and output, in order to avoid sending unnecessary data between the client and the server, the application should specify on SQLBindParameter() the parameter type of an input argument to be SQL_PARAM_INPUT and the parameter type of an output argument to be SQL_PARAM_OUTPUT. Those arguments that are both input and output have a parameter type of SQL_PARAM_INPUT_OUTPUT.

If the server is DB2 Universal Database Version 2.1 or later, or DB2 for MVS/ESA V4.1 or later, an application can call SQLProcedureColumns() to determine the type of a parameter in a procedure call. For more information, refer to "Registering Stored Procedures" below and SQLProcedureColumns - Get Input/Output Parameter Information for A Procedure.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]