ASSOCIATE LOCATOR statement

The ASSOCIATE LOCATOR statement gets the result set locator value for each result set returned by a stored procedure. The statement will be used in combination with the ALLOCATE CURSOR statement.

Syntax:

ASSOCIATE [RESULT SET] LOCATOR|LOCATORS ( <locator variables>, ... ) WITH PROCEDURE <procedure name>;

Example:

create procedure responder ()
language sql
result sets 1
begin
  declare mycur cursor with return to caller for
     select firstnme, lastname from employee order by lastname, firstnme;
  open mycur;
end!

 

create procedure caller (out firstname varchar(20), out lastname varchar(20))
language sql
begin
  declare loc result_set_locator varying;
  call responder();
  associate result set locator(loc) with procedure responder;
  allocate cur cursor for result set loc;
  open cur;
  fetch from cur into firstname, lastname;
  close cur;
end!

Another example can be found here.


Link to the DB2 Information Center: DB2 9.7 DB2 10.1 DB2 10.5