The into clause specifies the host program variables into which the values retrieved by the select are loaded. There must be a one-to-one correspondence between expressions in the select clause and the variables in the into clause. If the statement does not retrieve any rows, the variables are not modified. If the number of values retrieved from the database is different from the number of columns, an error is issued and the sqlwarn3 variable of the SQLCA is assigned the value W. Each result variable can have an indicator variable for null data.
Host language variables can be used as expressions in the select clause and the search_condition, in addition to their use in the into clause. Variables used in search_conditions must denote constant values and cannot represent names of database columns or include any operators. Host string variables can also substitute for the complete search condition.
The into clause can include a structure that substitutes for some or all of the variables. The structure is expanded by the preprocessor into the names of its individual variables. Therefore, placing a structure name in the into clause is equivalent to enumerating all members of the structure in the order in which they were declared.
If using a select * to retrieve into a structure, ensure that the members of the structure have a one-to-one correspondence to the columns in the result table.
To retrieve long varchar and long byte columns, specify a datahandler clause in place of the host language variable in the into clause. For details about data handler routines, see the chapter "Embedded SQL" and the Embedded SQL Companion Guide. The syntax for the datahandler clause is as follows:
DATAHANDLER(handler_routine ([handler_arg]))[:indicator_var]
When select statements are combined using the union clause, the into clause must appear only after the first list of select result expressions, because all result rows of the select statements that are combined by the union clause must be identical. The following example shows the correct use of host language variables in a union; result variables are specified only for the first select statement:
exec sql select ename, enumber
into :name, :number
from employee
union
select dname, dnumber
from directors
where dnumber < 100;