16.20 - Using CLIv2 to Consume Dynamic Result Sets - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

This example uses CLIv2 in an external stored procedure to execute an SQL request to call a stored procedure that returns dynamic result sets.

The external stored procedure does the following:
  • Drops and creates a table called TraceTable that it uses to trace the types of parcels that are returned to the external stored procedure as a result of calling the stored procedure.
  • Drops and creates a table called tab1.
  • Inserts 10 rows into tab1.
  • Calls the p1 stored procedure, which selects the 10 rows from the tab1 table. For each parcel returned, the external stored procedure inserts that into the TraceTable table.

The stored procedure that returns the result sets is defined like this:

REPLACE PROCEDURE P1 (IN OUT_SQLSTR VARCHAR(50))
DYNAMIC RESULT SETS 1
BEGIN
   DECLARE C1 CURSOR WITH RETURN ONLY TO CALLER FOR S1;
   PREPARE S1 FROM OUT_SQLSTR;
   OPEN C1;
END;

For details on the REPLACE PROCEDURE statement and the DYNAMIC RESULT SETS clause, see Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144. For details on the DECLARE CURSOR, PREPARE, and OPEN statements, see Teradata Vantage™ SQL Stored Procedures and Embedded SQL , B035-1148 .