Structured Query Language (SQL) - Cultural View of Technology
Structured Query Language (SQL) - Cultural View of Technology
Structured Query Language (SQL) - Cultural View of Technology
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Cursor (databases) 30<br />
Positioned update/delete statements<br />
Cursors can not only be used to fetch data from the DBMS into an application but also to identify a row in a table to<br />
be updated or deleted. The <strong>SQL</strong>:2003 standard defines positioned update and positioned delete <strong>SQL</strong> statements for<br />
that purpose. Such statements do not use a regular WHERE clause with predicates. Instead, a cursor identifies the<br />
row. The cursor must be opened and positioned on a row already using the FETCH statement.<br />
UPDATE table_name<br />
SET ...<br />
WHERE CURRENT OF cursor_name<br />
DELETE<br />
FROM table_name<br />
WHERE CURRENT OF cursor_name<br />
The cursor must operate on an updatable result set in order to successfully execute a positioned update or delete<br />
statement. Otherwise, the DBMS would not know how to apply the data changes to the underlying tables referred to<br />
in the cursor.<br />
Cursors in distributed transactions<br />
Using cursors in distributed transactions (X/Open XA Environments), which are controlled using a transaction<br />
monitor, is no different than cursors in non-distributed transactions.<br />
One has to pay attention when using holdable cursors, however. Connections can be used by different applications.<br />
Thus, once a transaction has been ended and committed, a subsequent transaction (running in a different application)<br />
could inherit existing holdable cursors. Therefore, an application developer has to be aware <strong>of</strong> that situation.<br />
Cursors in X<strong>Query</strong><br />
The X<strong>Query</strong> language allows cursors to be created using the subsequence() function.<br />
The format is:<br />
let $displayed-sequence := subsequence($result, $start, $item-count)<br />
Where $result is the result <strong>of</strong> the initial X<strong>Query</strong>, $start is the item number to start and $item-count is the number <strong>of</strong><br />
items to return.<br />
Equivalently this can also be done using a predicate:<br />
let $displayed-sequence := $result[$start to $end]<br />
Where $end is the end sequence.<br />
For complete examples see the X<strong>Query</strong> Wikibook [1] .