SQL Programming Manual for TAL
NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL—527887-001
3-21
INSERT
! Variable declarations:
EXEC SQL BEGIN DECLARE SECTION;
STRUCT employee^type(*);
BEGIN
INT empnum /SMALLINT UNSIGNED/;
STRING first^name[0:14];
STRING last^name[0:19];
INT deptnum /SMALLINT UNSIGNED/;
INT jobcode /SMALLINT UNSIGNED/;
INT(32) salary /INTEGER UNSIGNED/; ! scale is 2
... END;
STRUCT .emp(employee^type);
INT ind^1;
EXEC SQL END DECLARE SECTION;
...
! Executable statements:
ind^1 := -1; ! Set indicator variable
EXEC SQL
INSERT INTO =employee (first^name, last^name, salary)
VALUES (:emp.first^name,
:emp.last^name,
:emp.salary INDICATOR :ind^1);
To insert a value with scale (for example, a price or salary) into a database, use a host
variable of TAL FIXED or INT (32) data type and then use the SQL SETSCALE
function to specify the scale.
In this example uses the NULL keyword instead of an indicator variable:
EXEC SQL
INSERT INTO =employee (first^name, last^name, salary)
VALUES (:emp.first^name,
:emp.last^name,
NULL);
Inserting a Timestamp Value
This example inserts a timestamp value into COLUMN^A of TABLE^T. The
COLUMN^A definition specifies the data type TIMESTAMP DEFAULT CURRENT.
When the example inserts a row, NonStop SQL inserts the current timestamp but does
not know the timestamp value inserted.