SQL Programming Manual for TAL

Host Variables and Parameters
HP NonStop SQL Programming Manual for TAL527887-001
2-18
Using Indicator Variables for Null Values
Inserting a Null Value
These examples use indicator variables to insert a null value and to select from a
column that can return a null value. the TACL DEFINEs =RETIREES and
=SHIPMENTS are in effect for the respective tables.
This example uses an indicator variable to insert a null value:
! Variable declarations:
EXEC SQL BEGIN DECLARE SECTION;
INT empnum;
STRING retire^date[0:9];
INT retire^ind; ! indicator variable
EXEC SQL END DECLARE SECTION;
...
PROC insert^data;
BEGIN
empnum := 22346;
retire^ind := -1;
...
EXEC SQL
INSERT INTO =retirees (empnum, retire_date)
VALUES (:empnum,
:retire^date INDICATOR :retire^ind);
! It is not necessary to assign a value to
! retire^date in order to specify a null value.
...
END;
You can also use the NULL keyword instead of an indicator variable to insert a null
value:
PROC insert^data;
BEGIN
empnum := 22346;
EXEC SQL
INSERT INTO =retirees (empnum, retire_date)
VALUES (:empnum, NULL );
...
END;