You can access Db2 data that is not in a table by returning the value of an SQL expression in a host variable.
Procedure
To return the value of an SQL expression that does not include the value of a table column in host variable, use one of the following approaches:
- Use the SET host-variable assignment statement to set the contents of a host variable to the value of an expression.
EXEC SQL SET :hvrandval = RAND(:hvrand);
- Use the VALUES INTO statement to return the value of an expression in a host variable.
EXEC SQL VALUES RAND(:hvrand)
INTO :hvrandval;
- Use the following statement to select the expression from the Db2-provided EBCDIC table, named SYSIBM.SYSDUMMY1, which consists of one row.
EXEC SQL SELECT RAND(:hvrand)
INTO :hvrandval
FROM SYSIBM.SYSDUMMY1;