Skip to Main Content
  • Questions
  • cursor within cursor using forall is possible?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Chaitanya.

Asked: June 03, 2017 - 12:05 pm UTC

Last updated: June 05, 2017 - 5:01 am UTC

Version: 11g

Viewed 1000+ times

You Asked

HI TOM,

GOOD DAY!

cursor within cursor using forall is possible?

need to fetch records from all_objects in first cursor


and then need to delete records using object name in where clause in FORALL



and Connor said...

Well...that's a bit light on details or specifics, but here's something that *might* mean what you mean ...

SQL> create table t as select * from dba_objects;

Table created.

SQL> create index ix on t ( object_name );

Index created.

SQL>
SQL> declare
  2    cursor c is select * from all_objects;
  3
  4    type clist is table of c%rowtype;
  5    l_rows clist;
  6  begin
  7
  8    open c;
  9    fetch c bulk collect into l_rows;
 10    close c;
 11
 12    forall i in 1 .. l_rows.count
 13      delete from t
 14      where object_name = l_rows(i).object_name;
 15  end;
 16  /

PL/SQL procedure successfully completed.




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library