23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

E<strong>SQL</strong> elements and statements<br />

Examples<br />

324<br />

query_expression [ ORDER BY clause ] [FOR UPDATE clause ]<br />

A complete query expression.<br />

prepared_statement_name<br />

The name assigned to a prepared <strong>SQL</strong> statement in an earlier PREPARE statement.<br />

EXEC <strong>SQL</strong> WHENEVER <strong>SQL</strong>ERROR GOTO selerr ;<br />

EXEC <strong>SQL</strong> DECLARE stcur CURSOR FOR<br />

SELECT InvTransNum, Qty, OrderNum FROM PUB.InventoryTrans ;<br />

EXEC <strong>SQL</strong> OPEN stcur ;<br />

EXEC <strong>SQL</strong> WHENEVER NOT FOUND GOTO seldone ;<br />

EXEC <strong>SQL</strong> WHENEVER <strong>SQL</strong>ERROR GOTO selerr ;<br />

EXEC <strong>SQL</strong> PREPARE stmtid from :sel_stmt_v ;<br />

EXEC <strong>SQL</strong> DECLARE dyncur CURSOR FOR stmtid ;<br />

EXEC <strong>SQL</strong> OPEN dyncur ;<br />

EXEC <strong>SQL</strong> WHENEVER NOT FOUND GOTO seldone ;<br />

Notes • You must declare a cursor before any OPEN, FETCH, or CLOSE statement.<br />

• The scope of the cursor declaration is the entire source file in which it is declared. The<br />

operations on the cursor, such as OPEN, CLOSE, and FETCH statements, can occur only within<br />

the same compilation unit as the cursor declaration.<br />

• The use of a cursor allows the execution of the positioned forms of the UPDATE and DELETE<br />

statements.<br />

• If the DECLARE statement corresponds to a static <strong>SQL</strong> statement with parameter references:<br />

– The DECLARE statement must be executed before each execution of an OPEN statement<br />

for the same cursor.<br />

– The DECLARE statement and the OPEN statement that follows must occur within the<br />

same transaction within the same task.<br />

– If the statement contains parameter references to automatic variables or function<br />

arguments, the DECLARE statement and the following OPEN statement for the same<br />

cursor must occur within the same C function.<br />

Authorization<br />

None<br />

Related statements<br />

PREPARE, OPEN, FETCH, CLOSE SELECT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!