Friday, June 7, 2019

Simple Cursor and For Loop in Oracle

in oracle we can open cursor and need to start loop (while similar as SQL Server) so that we can process data what ever is coming in cursor.

In this post i am going to show you simplest code or plsql to do cursor and for loop of cursor.
See below syntax

set serveroutput on
declare
    cursor c2 is select * from user_tables;
begin
   for ii in c2 loop
    dbms_output.put_line(ii.table_name);
   end loop;
end;
/


In this cursor Oracle will automatically open and close the cursor before start and end of the program. so do not worry about the having 'open cursor' and 'close cursor' in your code.

No comments:

Post a Comment

web stats