Host variables
Host variables are or C variables that you use in embedded SQL statements to transfer data between database columns and the program.
When you use a host variable in an SQL statement, you must precede
its name with a symbol to distinguish it as a host variable. You can
use either of the following symbols:
- A colon (:) For example, to specify the host variable that is called hostvar as a connection name, use the following syntax:
EXEC SQL connect to :hostvar;
Using the colon (:) as a host-variable prefix conforms to ANSI SQL standards.
- A dollar sign ($) For example, to specify the host variable that is called hostvar as a connection name, use the following syntax:
EXEC SQL connect to $hostvar;
When you list more than one host variable within an SQL statement,
separate the host variables with commas (,). For example, the esql command
interprets the following line as two host variables, host1 and host2:
EXEC SQL select fname, lname into :host1, :host2 from customer;
If you omit the comma, esql interprets the second
variable as an indicator variable for the first host variable. The esql command
interprets the following line as one host variable, host1,
and one indicator variable, host2, for the host1 host
variable:
EXEC SQL select fname, lname into :host1 :host2 from customer;
Outside an SQL statement, treat a host variable as you would a regular C variable.