24 July, 2015

Implicit vs. Explicit cursors

Implicit vs. Explicit

 

Both the above are purely conceptual things and for Oracle engine, both are same. But implicit cursors are more efficient and easy to deal with.

 

Implicit

Explicit

begin

  for x in ( select * from t )

  loop

     process x;

   end loop;

end;

declare

   cursor c is select * from t;

   l_rec c%rowtype;

begin

   open c;

   loop

      fetch c into l_rec;

      exit when (c%notfound);

      process l_rec;

   end loop;

   close c;

end;

/

 

Both these have no performance benefit over the other. But for explicitly defined cursors, there is more code that needs to be written and hence chances of programmatic errors are more.