Data types in stored procedures
A stored procedure that is written in any language except REXX must declare each parameter that is passed to it. The definition for that stored procedure must also contain a compatible SQL data type declaration for each parameter.
For languages other than REXX
For all data types except LOBs, ROWIDs, locators, and VARCHARs (for C language), see the tables listed in the following table for the host data types that are compatible with the data types in the stored procedure definition. You cannot have XML parameters in an external procedure.
For LOBs, ROWIDs, VARCHARs, and locators, the following table shows compatible declarations for the assembler language.
SQL data type in definition | Assembler declaration |
---|---|
|
DS FL4 |
|
|
|
|
|
|
|
DS HL2,CL40 |
|
If PARAMETER VARCHAR NULTERM is specified or
implied:
If
PARAMETER VARCHAR STRUCTURE is specified:
|
Note:
|
For LOBs, ROWIDs, and locators, the following table shows compatible declarations for the C language.
SQL data type in definition | C declaration |
---|---|
|
unsigned long |
|
|
|
|
|
|
|
|
For LOBs, ROWIDs, and locators, the following table shows compatible declarations for COBOL.
SQL data type in definition | COBOL declaration |
---|---|
|
01 var PIC S9(9) COMP-5. |
|
|
|
|
|
|
|
|
For LOBs, ROWIDs, and locators, the following table shows compatible declarations for PL/I.
SQL data type in definition | PL/I |
---|---|
|
BIN FIXED(31) |
|
If n <= 32767: If n > 32767:
|
|
If n <= 32767: If n > 32767:
|
|
If n <= 16383: If n > 16383:
|
|
CHAR(40) VAR |
Tables of results: Each high-level language definition for stored procedure parameters supports only a single instance (a scalar value) of the parameter. There is no support for structure, array, or vector parameters. Because of this, the SQL statement CALL limits the ability of an application to return some kinds of tables. For example, an application might need to return a table that represents multiple occurrences of one or more of the parameters passed to the stored procedure. Because the SQL statement CALL cannot return more than one set of parameters, use one of the following techniques to return such a table:
- Put the data that the application returns in a Db2 table. The calling program can receive the
data in one of these ways:
- The calling program can fetch the rows from the table directly. Specify FOR FETCH ONLY or FOR READ ONLY on the SELECT statement that retrieves data from the table. A block fetch can retrieve the required data efficiently.
- The stored procedure can return the contents of the table as a result set. See Writing an external procedure to return result sets to a distributed client and Writing a program to receive the result sets from a stored procedure for more information.
- Convert tabular data to string format and return it as a character string parameter to the calling program. The calling program and the stored procedure can establish a convention for interpreting the content of the character string. For example, the SQL statement CALL can pass a 1920-byte character string parameter to a stored procedure, which enables the stored procedure to return a 24x80 screen image to the calling program.