Example: Input and Output Arguments in ODBC - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

Example: Input and Output Arguments in ODBC

The following example describes the usage of the stored procedures specifying input and output arguments in an ODBC application.

Consider the stored procedure spSample2 defined as follows:

     CREATE PROCEDURE spSample2(
       OUT p1   INTEGER,
       INOUT p2 INTEGER,
       IN p3    INTEGER)
      BEGIN
        SET p1 = p3;
        SET p2 = p2 * p3;
      END;

The arguments can be specified in the following format:

     SQLBindParameter(..., 1, SQL_PARAM_INPUT_OUTPUT, ..., SQLINTEGER,      ..., ..., AppVar2, sizeof(AppVar2), ...);
     SQLBindParameter(..., 2, SQL_PARAM_INPUT, ..., SQLINTEGER, ...,      ..., AppVar3, sizeof(AppVar3), ...);

where the second argument in SQLBindParameter() is the question mark number ordered sequentially from left to right, starting at 1.

Executing the stored procedure:

     {
     constchar *request = "CALL spSample2(p1, ?, ?)";
     ...
     ...
     SQLExecDirect(hstmt, request);
     ...
     ...
     }

Retrieving the output parameter values:

     SQLBindCol(..., 1, ..., AppVar1, ..., ...);
     SQLBindCol(..., 2, ..., AppVar2, ..., ...);

where the second argument in the SQLBindCol() is the parameter number of result data, ordered sequentially left to right, starting at 1.