SQL Programming Manual for TAL
Host Variables and Parameters
HP NonStop SQL Programming Manual for TAL—527887-001
2-8
Using Host Variables
Using Structures as Host Variables
Follow the guidelines below when you declare and use structures or fields within
structures as host variables.
INVOKE Directive. Use the INVOKE directive to declare structure descriptions
corresponding to SQL tables and views. The structure fields (which correspond to the
columns in the table or view) become host variables. For information about using the
INVOKE directive to create host variables, see Creating Host Variables With the
INVOKE Directive on page 2-20.
VARCHAR Type. Declare host variables that correspond to the SQL VARCHAR type
as TAL structures. See Table 2-1 on page 2-3 for an example of the TAL structure. For
these structures, you can refer to both the TAL structure name and the individual fields;
however, only the structure name is recognized as a host variable of SQL type
VARCHAR.
Structure Name References. You can refer to a structure name as a host variable
only if the structure:
•
Represents an item of SQL type VARCHAR
•
Is an SQLDA
•
Has an array of type STRING as its only field
For other TAL structures, you can refer to only the individual fields in the structure as
host variables, but you cannot refer to the structure name. Except for the above cases,
you must use the structure name with the field name to reference a host variable that is
a field within a structure. For example, the structure named EMPLOYEE^INFO
contains the EMPID, EMPNAME, and SALARY host variables.
EXEC SQL BEGIN DECLARE SECTION;
STRUCT .employee^info;
BEGIN
STRING empid[0:9];
STRING empname[0:19];
FIXED(2) salary;
END;
EXEC SQL END DECLARE SECTION;
When you use these host variables in an SQL statement, refer to them by the structure
and field names. For example:
EXEC SQL SELECT empid, empname, salary
INTO :employee^info.empid, :employee^info.empname,
:employee^info.salary
FROM =employee
WHERE empid = 12345;