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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example<br />

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

/*<br />

** One way to limit the number of rows returned is to<br />

** set a new value for "j" here. As supplied in the SPORTS2000 database,<br />

** the PUB.InventoryTrans table contains 75 rows.<br />

*/<br />

j = 100;<br />

for (i = 0; i < j; i++)<br />

{<br />

EXEC <strong>SQL</strong> FETCH dyncur INTO<br />

:int_p1_v, :int_p2_v, :char_p_v ;<br />

if (i == 0)<br />

{<br />

printf (" 1st col 2nd col 3rd col");<br />

printf (" ------- ------- --------");<br />

}<br />

printf (" %d %d %s ",<br />

int_p1_v, int_p2_v, char_p_v) ;<br />

}<br />

Notes • A FETCH operation requires that the cursor be open.<br />

• The positioning of the cursor for each FETCH operation is as follows:<br />

– The first time you execute a FETCH statement after opening the cursor, the cursor is<br />

positioned to the first row of the active set.<br />

– Subsequent FETCH operations advance the cursor position in the active set. The next<br />

row becomes the current row.<br />

– When the current row is deleted using a positioned DELETE statement, the cursor is<br />

positioned before the row after the deleted row in the active set.<br />

• The cursor can only be moved forward in the active set by executing FETCH statements. To<br />

move the cursor to the beginning of the active set, you must CLOSE the cursor and OPEN it<br />

again.<br />

• If the cursor is positioned on the last row of the active set or if the active set does not<br />

contain any rows, executing a FETCH will return the status code <strong>SQL</strong>_NOT_FOUND in the<br />

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

• After a successful FETCH, the total row count fetched so far for this cursor is returned in<br />

sqlca.sqlerrd[2]. The count is set to zero after an OPEN cursor operation.<br />

• You can FETCH multiple rows in one FETCH operation by using array variables in the INTO<br />

clause. The <strong>SQL</strong>_NOT_FOUND status code is returned in the <strong>SQL</strong>CA when the end of the active<br />

set is reached, even if the current FETCH statement returns one or more rows.<br />

• If you use array variables in a FETCH statement, the array sizes are set to the number of<br />

rows fetched after the FETCH statement is executed.<br />

Authorization<br />

None<br />

333

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

Saved successfully!

Ooh no, something went wrong!