1

Please help me with my Oracle procedure question. In my package I have a procedure and I want to declare a cursor which uses dynamic queries.

type DocList IS REF CURSOR;
curDocList DocList;
.
.
.
OPEN curDocList FOR v_sql;   --v_sql has dynamic sql
...
FOR recDocStatusList IN curDocList 
      LOOP

When I am trying to use - FOR recDocStatusList IN curDocList it is giving me the error: [Error] PLS-00221 (2262: 34): PLS-00221: 'CURDOCLIST' is not a procedure or is undefined.

Please help me correcting the issue.

1 Answer 1

1

If you're willing to iterate the cursor, you can perform it without using a FOR loop.

Option 1:

  LOOP
    FETCH curDocList INTO recDocStatusList;
    EXIT WHEN curDocList%NOTFOUND;
    ...
  END LOOP;

Option 2:

FETCH curDocList INTO recDocStatusList;
WHILE (curDocList%FOUND)
LOOP
    ...
    FETCH curDocList INTO recDocStatusList;
END LOOP;

A few annotations:

  • Remember to declare recDocStatusList at first.
  • Both options are following the OPEN ... FOR line.
  • Don't forget to CLOSE the cursor at the end.
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Neria. In the first place, the compile error is saying 'CURDOCLIST' is not a procedure. So will the above change of looping style help?
Yes, the exception description doesn't properly reflect the cause. As Tom Kyte said in this article, "you can only loop over unopened cursors implicitly", and since a REF CURSOR should be opened, it wouldn't work. "ref cursors are ALWAYS explicit cursors".
Yep, and therefore you should also FETCH and CLOSE the cursor explicitly. Hence, in my examples I fetched it. Don't forget to close it after the loop.
Ok I will try...a quick question. I haven't declared recDocStatusList. Is this correct: "recDocStatusList DocList" in declaration
You haven't post it, but it should be a record of the v_sql ROWTYPE. Edit: Nope, it's incorrect.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.