SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Static Rowsets
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
7-14
Inserting Rows From Rowset Arrays
Inserting Rows From Rowset Arrays
The INSERT statement using rowsets inserts multiple rows into a table from host
variable arrays. To insert data, a program moves the new values to the array of host
variables that have been declared as rowsets and then executes an INSERT statement
to transfer the values from the host variable arrays to the table.
Use this general syntax:
For complete syntax, see the INSERT statement in the SQL/MX Reference Manual.
Example
This example inserts multiple rows (JOBCODE and JOBDESC columns) from host
variable arrays into the JOB table:
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
ROWSET[5] unsigned NUMERIC (4) hva_jobcode;
ROWSET[5] VARCHAR hva_jobdesc[19];
...
long numrows;
EXEC SQL END DECLARE SECTION;
...
/* Populate the rowset in some way. */
hva_jobcode[0] = 100;
strcpy(hva_jobdesc[0],"PROJECT MANAGER");
hva_jobcode[1] = 200;
strcpy(hva_jobdesc[1],"PROGRAM MANAGER");
hva_jobcode[2] = 300;
strcpy(hva_jobdesc[2],"QUALITY SUPERVISOR");
hva_jobcode[3] = 400;
strcpy(hva_jobdesc[3],"TECHNICAL OFFICER");
hva_jobcode[4] = 500;
strcpy(hva_jobdesc[4],"EXECUTIVE OFFICER");
...
EXEC SQL INSERT INTO persnl.job (jobcode, jobdesc)
VALUES (:hva_jobcode, :hva_jobdesc);
...
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 sqlstate pic x(5).
01 numrows pic 9(9) comp.
01 rs.
02 ROWSET[5] hvajobcode pic 9(4) comp.
02 ROWSET[5] hvajobdesc pic x(18).
EXEC SQL END DECLARE SECTION END-EXEC.
...
***** Populate the rowset in some way *****
Move 100 to hvajobcode[1]
Move "PROJECT MANAGER" to hvaprojdesc[1]
Move 200 to hvajobcode[2]
INSERT INTO table-name [(column [,column]...)]
VALUES (:hostvar-array [,:hostvar-array]...)
C
COBOL