SQL Programming Manual for Pascal
Host Variables and Parameters
HP NonStop SQL Programming Manual for Pascal—528614-001
2-11
Using Host Variables
If columns can contain null values, a program should use indicator variables when
referring to those columns. A program might:
•
Insert null values into the database with an INSERT or UPDATE statement
•
Retrieve null values from the database with a SELECT statement
•
Specify null values in a WHERE clause in an UPDATE, DELETE, or SELECT
statement
You can also use indicator variables with the INSERT, UPDATE, DELETE, and
SELECT statements. You can use the keyword NULL, as shown in the subsequent
examples in this section.
Examples
The following examples show two ways to insert null values. DEFINEs, preceded by an
equals sign (=), are in effect for the table.
The following example uses an indicator variable to insert a null value:
{ Variable declarations: }
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL INVOKE PERSNL.EMPLOYEE AS EMP_TBL_TYPE;
{ The invoked TYPE definition is: }
{ TYPE }
{ EMP_TBL_TYPE = RECORD }
{ EMPNUM : CARDINAL; }
{ FIRST_NAME : FSTRING(15); }
{ LAST_NAME : FSTRING(20); }
{ DEPTNUM : CARDINAL; }
{ JOBCODE : CARDINAL; }
{ SALARY : INT32; {* scale is 2 *} }
{ END; }
...
VAR
EMP_TBL : EMP_TBL_TYPE;
IND_1 : INT16;
...
EXEC SQL END DECLARE SECTION;
{ Executable code: }
IND_1 := -1;
EXEC SQL
INSERT INTO =EMPLOYEE
VALUES (:EMP_TBL.EMPNUM, :EMP_TBL.FIRST-NAME,
:EMP_TBL.LAST_NAME, :EMP_TBL.DEPTNUM,