Inserting A Single Row; Inserting A Null Value - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Data Retrieval and Modification

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;
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
...
}
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,
This example uses the NULL keyword instead of an indicator variable:
EXEC SQL INSERT INTO persnl.employee
VALUES (:emp.empnum, :emp.first_name,
HP NonStop SQL/MP Programming Manual for C—429847-008
(jobcode, jobdesc)
VALUES (:hv_jobcode, :hv_jobdesc) ;
:emp.last_name, :emp.deptnum, :emp.jobcode,
:emp.salary INDICATOR :ind_1);
:emp.last_name, :emp.deptnum, :emp.jobcode,
NULL);
/* host variables */
4-9
Inserting a Single Row

Advertisement

Table of Contents
loading

Table of Contents