SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Simple and Compound Statements
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
5-5
Inserting Rows
INSERT statement to transfer the values from the host variables to the table. Use this 
general syntax: 
For complete syntax, see the INSERT statement in the SQL/MX Reference Manual.
To execute an INSERT statement, a program must have INSERT privileges for each 
column in the table receiving the data. 
After an INSERT statement executes, NonStop SQL/MX returns a value to the 
SQLSTATE variable. If a data exception occurs during the insertion process, the value 
of SQLSTATE is 22xxx (data exception). The class value is 22, and the subclass can 
be a variety of conditions, depending on the nature of the data being inserted. For 
information on SQLSTATE values, see Section 13, Exception Handling and Error 
Conditions.
Inserting Rows
You can insert a single row or multiple rows of data by using the VALUES clause that 
specifies a row or rows of host variables.
This example inserts a row (the JOBCODE and JOBDESC columns) into the JOB 
table. The host variables are declared as global host variables, the Declare Section 
occurs before the definition of main(): 
Example
void insert_job(void); 
...
EXEC SQL BEGIN DECLARE SECTION;
 char SQLSTATE[6];
 unsigned NUMERIC (4) hv_jobcode; /* global host variables */
 VARCHAR hv_jobdesc[19];
EXEC SQL END DECLARE SECTION;
...
int main()
{
...
... /* Input the values of hv_jobcode and hv_jobdesc */ 
insert_job(); 
...
return 0;
} /* end main */
void insert_job(void) { 
EXEC SQL INSERT INTO persnl.job (jobcode, jobdesc)
 VALUES (:hv_jobcode, :hv_jobdesc); 
} /* end insert_job */
INSERT INTO table-name (column [,column]...)
 VALUES (:hostvar [,:hostvar]...) 
C










