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 />

Syntax<br />

Example<br />

338<br />

OPEN<br />

Executes a prepared <strong>SQL</strong> query associated with a cursor and creates a result set composed of<br />

the rows that satisfy the query. This set of rows is called the active set.<br />

OPEN cursor_name<br />

[ USING { [ <strong>SQL</strong> ] DESCRIPTOR structure_name<br />

| :host_variable [ [ INDICATOR ] :ind_variable ] , ... } ] ;<br />

cursor_name<br />

An identifier named in an earlier DECLARE CURSOR statement.<br />

USING [ <strong>SQL</strong> ] DESCRIPTOR structure_name<br />

Directs the <strong>SQL</strong> engine to create the result set in storage addressed by the identified<br />

<strong>SQL</strong>DA structure.<br />

USING :host_variable [ [ INDICATOR ] :ind_variable ]<br />

Directs the <strong>SQL</strong> engine to create the result set in storage addressed by host variables.<br />

/*<br />

** 5. Name WHENEVER routine to handle <strong>SQL</strong>ERROR.<br />

**<br />

** 6. DECLARE cursor for the SELECT statement.<br />

** NOTE: You must set input parameter values before OPEN CURSOR.<br />

** The static query in this program does not have input parameters.<br />

**<br />

** 7. OPEN the cursor.<br />

** NOTE: For static statements, if a DECLARE CURSOR<br />

** statement contains references to automatic variables,<br />

** the OPEN CURSOR statement must be in the same C function.<br />

**<br />

** 8. Name WHENEVER routine to handle NOT FOUND condition.<br />

*/<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,<br />

OrderNum FROM PUB.InventoryTrans ;<br />

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

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

Notes • Executing an OPEN cursor statement sets the cursor to the open state.<br />

• After the OPEN cursor statement is executed, the cursor is positioned just before the first<br />

row of the active set.<br />

• For a single execution of an OPEN cursor statement, the active set does not change and the<br />

host variables are not re-examined.<br />

• If you elect to retrieve a new active set and a host variable value has changed, you must<br />

CLOSE the cursor and OPEN it again.

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

Saved successfully!

Ooh no, something went wrong!