SQL Programming Manual for TAL
Host Variables and Parameters
HP NonStop SQL Programming Manual for TAL—527887-001
2-10
Using Host Variables
! Reference to an integer within an array
! of integers in a structure:
EXEC SQL SELECT integer^value INTO
:outer^struct.int^array[1]
FROM table1;
! A reference to an integer within nested structures:
EXEC SQL SELECT integer^value INTO
:outer^struct.nested^struct^1.nested^struct^2.int^1
FROM table1;
! A reference to a VARCHAR item:
EXEC SQL SELECT character^string INTO
:first^dim.second^dim.third^dim
FROM table1;
In this example, after the VARCHAR item is accessed, NonStop SQL sets:
•
FIRST^DIM.SECOND^DIM.THIRD.DIM.NAME to CHARACTER^STRING
•
FIRST^DIM.SECOND^DIM.THIRD.DIM.LEN to the byte length of
CHARACTER^STRING
Structures as Character Host Variables. A value from an SQL column of SQL data
type CHAR can be stored into a host variable that is a structure containing a single
array of TAL type STRING. Reference the structure either directly through the structure
name, or indirectly through a structure pointer.
In this example, PEOPLE is an SQL table that contains the 10-character column
EMPNAME. You can use the names DIRECT^STRUCT, INDIRECT^STRUCT, and
STRUCT^POINTER as host variables to store EMPNAME.
! Host variable declarations:
EXEC SQL BEGIN DECLARE SECTION;
STRUCT direct^struct;
BEGIN
STRING name [0:9];
END;
INT .struct^pointer(direct^struct);
STRUCT .indirect^struct;
BEGIN
STRING name [0:9];
END;
EXEC SQL END DECLARE SECTION;
To use the host variable DIRECT^STRUCT, specify:
EXEC SQL
SELECT empname INTO :direct^struct FROM people;
If you make STRUCT^POINTER point to DIRECT^STRUCT, you can also specify:
EXEC SQL
SELECT empname INTO :struct^pointer FROM people;