I'd like to declare a cursor to loop over a table variable, something like this:
1. DECLARE temp = SELECT a, b,c from atable;
2. DECLARE CURSOR cur FOR SELECT * FROM :temp;
This code, however, results in the error message on line 1:
Syntax error. "=" is incorrect or misplaced.
Changing the code to this:
1. temp = SELECT a, b,c from atable;
2. DECLARE CURSOR cur FOR SELECT * FROM :temp;
gives a different error message on line 2:
Syntax error. "DECLARE" is incorrect or misplaced.
Is this possible? I was already thinking of moving the DECLARE cursor into a second procedure that is called from this one. But there must be a better way..