Tutorial Chapter 4: Query by Example / Implementing Query-by-Example |
The STRING created in the query-by-example is not valid for execution. The PREPARE instruction sends the text of the string to the database server for parsing, validation, and to generate the execution plan.
PREPARE cust_cnt_stmt FROM sql_text
EXECUTE cust_cnt_stmt INTO cust_cnt
Since the SQL statement will only return one row (containing the count) the INTO syntax of the EXECUTE instruction can be used to store the count in the local variable cust_cnt. (The function cust_select illustrates the use of database cursors with SQL SELECT statements.)
FREE cust_cnt_stmt