Multirow Select Statement - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Data Retrieval and Modification
WHERE
ORDER BY partnum
BROWSE ACCESS;
...
void list_func(void)
{
EXEC SQL OPEN list_by_partnum;
EXEC SQL FETCH list_by_partnum
...
}

Multirow SELECT Statement

When used with a cursor, a SELECT statement can return multiple rows from a table or
protection view, one row at a time. A cursor uses a FETCH statement to retrieve each
row and store the selected column values in host variables. The program can then
process the values (for example, list or save them in an array).
To run a SELECT statement, a process started by the program must have read access
to all tables, protection views, and the underlying tables of shorthand views used in the
statement. For information about process access, see
page 7-1.
All statements that refer to the cursor, including the DECLARE CURSOR, OPEN,
FETCH, and CLOSE statements, must be within the same scope.
This example uses the get_name_address cursor to return the name and address of
all customers within a certain range from the CUSTOMER table. For data consistency,
the SELECT statement includes the REPEATABLE ACCESS clause to lock the rows.
The BETWEEN clause specifies the range of zip codes, and the ORDER BY clause
sorts the rows by zip code (POSTCODE).
EXEC SQL BEGIN DECLARE SECTION;
char begin_code[11], end_code[11];
EXEC SQL INVOKE =customer AS customer_struct;
struct customer_struct customer_row;
...
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE get_name_address CURSOR FOR
SELECT custname, street, city, state, postcode
FROM
=customer
WHERE
postcode BETWEEN :begin_code AND :end_code
ORDER BY postcode
REPEATABLE ACCESS;
...
void list_customers(void)
{
HP NonStop SQL/MP Programming Manual for C—429847-008
partnum
>= :parts_rec.partnum
INTO
:parts_rec.partnum,
:parts_rec.partdesc,
:parts_rec.price,
:parts_rec.qty_available;
Required Access Authority
4-21
Multirow SELECT Statement
on

Advertisement

Table of Contents
loading

Table of Contents