This is what I am trying to achieve:
-
define a cursor
-
which return me list of rows
-
use the rows to do some modify tables
-
repeat 2 and 3 until cursor returns no result.
this is what I have done so far
DECLARE
CURSOR c1 IS
[My SQL HERE];
BEGIN
FOR r1 in c1 LOOP
[modify tables]
END;
question is where do I put the while? I would do it before the for loop. but whats the syntax in pl/sql to describe c1 has result?
Note after c1 fullly finish I need to rerun the cursor code. Make another iteration . Because the result will be different. That’s why I needed the while
The answer is combine ‘while’ with ‘for ‘. Obviously only if you want to run the cursor multiple times, because you are update/alter something inside the cursor, and the condition changed, thus you need to re-run the cursor again.
here is the basic structure:
e.g