A cursor may be used to read a record from a table, as a cursor is able to execute a SELECT statement. The cursor fields are fetched into local variables and the content of the local variables modified as needed. One or more local variables can then be written out to a pipe.
Below is an example that shows how to read a record from a table and store the record fields in local variables named
acity and
acompany. After changing the content of
acity from 'Union City' to 'I am travelling to Union City' and changing the content of
acompany from 'Able Computing' to 'I work for a company whose name is Able Computing', the record is written to a pipe.
PROCEDURE pGetRecord(OUT c2 PIPE(mydestination VARCHAR, mycompany VARCHAR))
BEGIN
DECLARE c1 CURSOR;
DECLARE acity VARCHAR;
DECLARE acompany VARCHAR;
open c1 for SELECT City, CompanyName from /shared/examples/ds_orders/tutorial/customers;
FETCH c1 INTO acity, acompany;
set acity = 'I am travelling to ' || acity;
set acompany= 'I work for a company whose name is ' || acompany;
INSERT INTO c2 (mydestination, mycompany) VALUES (acity, acompany);
END
The output of the procedure is:
mydestination : I am travelling to Union City
mycompany : I work for a company whose name is Able Computing