Accessing DB2 data that is not in a table
You can access DB2® data that is not in a table by returning the value of an SQL expression in a host variable.
About this task
The expression does not include a column of a table. The three ways to return a value in a host variable are shown in the following examples.
Example: To set the contents
of a host variable to the value of an expression, use the SET host-variable
assignment statement:
EXEC SQL SET :hvrandval = RAND(:hvrand);
Example: To return the value of an expression
in a host variable, use the VALUES INTO statement:
EXEC SQL VALUES RAND(:hvrand)
INTO :hvrandval;
Example: To select the expression from the DB2-provided EBCDIC
table, named SYSIBM.SYSDUMMY1, which consists of one row, use the
following statement:
EXEC SQL SELECT RAND(:hvrand)
INTO :hvrandval
FROM SYSIBM.SYSDUMMY1;
Parent topic: Accessing data from application programs