Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

2.2 Cursor usage

Table retrieval results usually consist of multiple rows. A cursor is used by the UAP to retrieve rows one at a time from the entire set of retrieved rows.

This section explains how to retrieve data using a cursor and how to use the cursor to update a retrieved row.

For details about how to use a cursor, see 3.5 Use of a cursor.

Organization of this section
(1) Retrieval using a cursor
(2) Using a cursor to update the row retrieved
(3) Retrieval without using a cursor (single row retrieval)

(1) Retrieval using a cursor

When table retrieval results consist of multiple rows or when retrieving data dynamically after preprocessing the SQL statement with the PREPARE statement, a cursor is used to retrieve the individual rows.

When retrieval results consist of one or fewer rows, it is possible to use the single row SELECT statement for retrieval instead of a cursor.

For details about the PREPARE and single row SELECT statements, see the HiRDB Version 8 SQL Reference manual.

As an example of using a cursor to retrieve multiple rows, the UAP below retrieves product codes and unit prices from a stock table:

[Figure]

(2) Using a cursor to update the row retrieved

When multiple rows are retrieved, a cursor is used to update the rows one at a time.

Although the single row SELECT statement can be used to update a retrieval that consists of one row or less, use of a cursor results in better processing efficiency.

As an example of using a cursor to update rows one at a time, the UAP below reduces the unit price of each product in the stock table by 10% (multiplies by 0.9):

[Figure]

(3) Retrieval without using a cursor (single row retrieval)

As an example of a retrieval that does not use a cursor, the UAP below makes a count of the items in the stock table and sets the results in an embedded variable.

[Figure]