SQL/MP Programming Manual for C
Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for C—429847-008
4-9
Inserting a Single Row
Inserting a Single Row 
This INSERT statement inserts a row (JOBCODE and JOBDESC columns) into the 
JOB table: 
EXEC SQL BEGIN DECLARE SECTION;
short hv_jobcode; /* host variables */ 
char hv_jobdesc[18];
... 
EXEC SQL END DECLARE SECTION;
...
void insert_job(void)
{ 
/* Set the values of hv_jobcode and hv_jobdesc */ 
... 
EXEC SQL INSERT INTO persnl.job 
 (jobcode, jobdesc)
 VALUES (:hv_jobcode, :hv_jobdesc) ; 
... 
}
If the INSERT operation fails, check for SQL error 8227, which indicates you attempted 
to insert a row with an existing key (primary or unique alternate). 
Inserting a Null Value
This example inserts a row into the EMPLOYEE table and sets the SALARY column to 
a null value using an indicator variable: 
/* Variable declarations: */
EXEC SQL BEGIN DECLARE SECTION;
 EXEC SQL INVOKE persnl.employee AS emp_tbl;
 struct emp_tbl emp;
 ...
 short ind_1;
EXEC SQL END DECLARE SECTION;
...
/* Executable statements: */
ind_1 = -1;
EXEC SQL INSERT INTO persnl.employee 
 VALUES (:emp.empnum, :emp.first_name,
 :emp.last_name, :emp.deptnum, :emp.jobcode,
 :emp.salary INDICATOR :ind_1);
This example uses the NULL keyword instead of an indicator variable: 
EXEC SQL INSERT INTO persnl.employee 
 VALUES (:emp.empnum, :emp.first_name, 
 :emp.last_name, :emp.deptnum, :emp.jobcode,
 NULL);










