Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cursor FOR LOOP vs. FOR LOOP with SELECT hard coded.

jflackJan 15 2021

There shouldn't be a difference between:

DECLARE
  CURSOR my_curs IS SELECT employee_name FROM employees;
BEGIN
  FOR my_rec IN my_curs LOOP
    -- do stuff
  END LOOP;
END;

And

BEGIN
  FOR my_rec IN (SELECT employee_name FROM employees) LOOP
    -- do stuff
  END LOOP;
END;

Right? I'm getting different results, but then my query is quite a bit more complicated, so it may be my bug. Might even have a slight difference that I am missing. This is just a sanity check.

This post has been answered by Solomon Yakobson on Jan 15 2021
Jump to Answer
Comments
Post Details
Added on Jan 15 2021
7 comments
35,600 views