Example 1: Write the embedded statements in a COBOL program that will:
EXEC SQL DECLARE C1 CURSOR FOR SELECT DEPTNO, DEPTNAME, MGRNO FROM DEPARTMENT WHERE ADMRDEPT = 'A00' END-EXEC. EXEC SQL OPEN C1 END-EXEC.
Example 2: Code an OPEN statement to associate a cursor DYN_CURSOR with a dynamically defined select-statement in a C program. Assume each prepared select-statement always defines two items in its select list with the first item having a data type of integer and the second item having a data type of VARCHAR(64). (The related host variable definitions, PREPARE statement, and DECLARE CURSOR statement are also shown in the example below.)
EXEC SQL BEGIN DECLARE SECTION; static short hv_int; char hv_vchar64[64]; char stmt1_str[200]; EXEC SQL END DECLARE SECTION; EXEC SQL PREPARE STMT1_NAME FROM :stmt1_str; EXEC SQL DECLARE DYN_CURSOR CURSOR FOR STMT1_NAME; EXEC SQL OPEN DYN_CURSOR USING :hv_int, :hv_vchar64;
Example 3: Code an OPEN statement as in example 3, but in this case the number and data types of the items in the select statement are not known.
EXEC SQL BEGIN DECLARE SECTION; char stmt1_str[200]; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLDA; EXEC SQL PREPARE STMT1_NAME FROM :stmt1_str; EXEC SQL DECLARE DYN_CURSOR CURSOR FOR STMT1_NAME; EXEC SQL OPEN DYN_CURSOR USING DESCRIPTOR :sqlda;
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.