17.05 - Example: Input and Output Arguments in ODBC - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

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.