Preparing SELECT statement

SELECT statement can be used directly in the 4GL code, or it may be prepared. If the prepared SELECT statement contains the INTO TEMP clause, it can only be executed by means of the EXECUTE statement. If the SELECT statement does not contain the INTO TEMP clause, the cursor can retrieve the rows selected by such statement with the help of the FOREACH statement or the OPEN and FETCH statements.

FOREACH statement cannot be used with the prepared SELECT statement that contains a question mark.

 

The prepared SELECT statement can include the FOR UPDATE clause. Such SELECT statements are usually used together with the FOR UPDATE cursor declaration. If the example below, the SELECT statement is prepared from a variable:

DEFINE sql_stmt CHAR(2032)

LET sql_stmt = "SELECT * FROM account_info", "WHERE acc_id BETWEEN ? and ?", " FOR UPDATE"

PREPARE p_act_arr FROM sql_stmt

DECLARE acc_cur CURSOR FOR p_act_arr

OPEN acc_cur USING low_acc, high_acc

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.