SQL Programming Manual for TAL
Host Variables and Parameters
HP NonStop SQL Programming Manual for TAL—527887-001
2-9
Using Host Variables
Structure Pointers. Although you cannot use a pointer by itself as a host
variable, you can refer to a field in a structure by using a structure pointer. For
example, you can use this host variable declaration and reference:
! Declaration:
EXEC SQL BEGIN DECLARE SECTION;
STRUCT s^template(*);
BEGIN
INT field1; ! Fields cannot be pointers in SQL
INT field2;
END;
STRING .EXT s^ptr (s^template); ! Structure pointer
EXEC SQL END DECLARE SECTION;
! Reference:
EXEC SQL SELECT col1 INTO :s^ptr.field1 FROM tbl1;
You can also use a structure as a host variable by:
•
Using array indexing within the structure
•
Allowing a field in the structure to be a substructure or an array
These examples show TAL structures that you can use as host variables:
! Substructures and array within a structure:
STRUCT .outer^struct; ! Structure
BEGIN
INT int^array[0:4]; ! Array
STRUCT sub^struct^1; ! Substructure
BEGIN
STRUCT sub^struct^2; ! Substructure
BEGIN
INT int^1;
INT int^2;
END;
END;
END;
! A three-dimensional structure of VARCHAR items:
STRUCT .first^dim[0:3];
BEGIN;
STRUCT second^dim[0:3];
BEGIN
STRUCT third^dim[0:3];
BEGIN
INT len;
STRING name[0:19];
END;
END;
END;