USING Clause
- A SELECT statement with input parameters in its WHERE clause
- An EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement with input parameters as arguments to its user-defined function
- An INSERT statement with input parameters in its VALUES clause (in ESQL/C).
In SPL routines, you must specify these parameters as SPL variables.
- You can specify one or more host variables.
- You can specify a system-descriptor area.
- You can specify a pointer to an sqlda structure.
For more information, see PREPARE statement.
If you know the number and the order of parameters to be supplied at runtime and their data types, you can define the parameters that are needed by the statement as host variables in your program. You pass parameters to the database server positionally, by opening the cursor with the USING keyword, followed by the names of the variables in their sequential order. These variables are matched with the SELECT or EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement question-mark ( ? ) placeholders in a one-to-one correspondence, from left to right.
You cannot include indicator variables of ESQL/C in the list of variables. To use an indicator variable, you must include the SELECT or EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement text as part of the DECLARE statement, rather than the identifier of a prepared statement.
sprintf (select_1, "%s %s %s %s %s",
"SELECT o.order_num, sum(total price)",
"FROM orders o, items i",
"WHERE o.order_date > ? AND o.customer_num = ?",
"AND o.order_num = i.order_num",
"GROUP BY o.order_num");
EXEC SQL prepare statement_1 from :select_1;
EXEC SQL declare q_curs cursor for statement_1;
EXEC SQL open q_curs using :o_date, :o.customer_num;
stcopy ("EXECUTE FUNCTION one_func(?, ?)", exfunc_stmt);
EXEC SQL prepare exfunc_id from :exfunc_stmt;
EXEC SQL declare func_curs cursor for exfunc_id;
EXEC SQL open func_curs using :arg1, :arg2;