Was this helpful?
Host Language Variables
Embedded OpenSQL allows host language variables to be used for many elements of embedded OpenSQL statements. Host language variables can be used to transfer data from the database into the program and vice versa. Host language variables can also replace the search condition in a WHERE clause.
Host language variables can be used to specify:
Database expressions—Variables can generally be used wherever expressions are allowed in embedded OpenSQL statements, such as in target lists and predicates. Variables must contain constant values and cannot represent names of database columns or include any operators.
Search conditions—A WHERE clause can be specified in a variable. The entire WHERE clause must be contained in the variable. For example, to retrieve all columns for employees who earn more than the average salary:
wherevar = 'salary>(select avg(salary)
from employee)'
exec sql select ename
into :name
from employee
where :wherevar
Receiving variables—A host variable can be used to specify the objects of the INTO clause of the SELECT and FETCH statements. The INTO clause is the means by which values retrieved from the database are transferred to host language variables.
Other statement arguments—The statement descriptions in this guide note which arguments can be specified using host language variables.
A host language variable can be a single variable or a structure.
All host language variables must be declared to embedded OpenSQL before you can use them in embedded OpenSQL statements. The names of these variables cannot be keywords reserved by Ingres.
The following sections describe how to use host language variables. For language‑specific details, see the Embedded SQL Companion Guide.
Last modified date: 11/28/2023