SQL Programming Manual for TAL
NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL—527887-001
3-20
INSERT
EXEC SQL
INSERT INTO table1
(column1,
column2,
column3,
column4)
VALUES (:host^var1,
:host^var2,
:host^var3,
:host^var4)
ANYWHERE ;
The previous example assumes that the organization of the table is relative. The
INSERT statement supplies values for the four named columns. The system supplies
the value for the system key (SYSKEY). Any other columns in the table receive default
values (either specified defaults or the system default). If any columns are defined as
NO DEFAULT, the insert operation fails because the values were not supplied.
The INSERT statement contains the ANYWHERE clause because the table
organization is relative. ANYWHERE causes the row to be inserted wherever space is
available. If you specify APPEND instead of ANYWHERE, the row is added to the end
of the table.
For a dynamic SQL program, the INSERT statement must be in the same procedure
as all other dynamic SQL statements that refer to the SQL statement being processed.
This table shows s the SQLCODE values that NonStop SQL returns after an INSERT
statement:
After a successful insert operation, the SQLCA structure contains the exact number of
rows inserted. To obtain the contents of the SQLCA, use the SQLCADISPLAY or
SQLCATOBUFFER procedure.
Inserting Null Values
This example inserts an employee record into the EMPLOYEE table and sets the
SALARY column to a null value using an indicator variable. This example uses the
TACL DEFINE name =EMPLOYEE for the EMPLOYEE table.
SQLCODE Value Description
0 The INSERT statement was successful.
100 No rows qualified for an INSERT through a SELECT specification.
< 0 An error occurred; SQLCODE contains the error number.
> 0 (not 100) A warning occurred; SQLCODE contains the first warning number.