forExecute Immediate
を使用して、 pl/sql ブロックFORALL
で収集します。BULK
FORALL i in rowid.FIRST ..rowid.LAST
Execute Immediate 'Delete table_name where rowid '=rowid(i)
上記のことは機能しません。誰でもinsert
andの構文を教えてもらえますdelete
か?
これを実現する方法の例を次に示します。
create table brainoverflow as ( select * from all_objects );
select count(*) from brainoverflow;
declare
type ri is table of rowid;
rowids ri;
begin
select rowid bulk collect into rowids from brainoverflow;
for i in rowids.first .. rowids.last loop
execute immediate ('delete brainoverflow where rowid='''||rowids(i)||'''');
end loop;
end;
/
select count(*) from brainoverflow;
SQL*Plus での実行:
oracle@stormwind:~$ sqlplus phil/phil
SQL*Plus: Release 11.2.0.3.0 Production on Fri May 25 11:37:40 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table brainoverflow as ( select * from all_objects );
Table created.
SQL> select count(*) from brainoverflow;
COUNT(*)
----------
72440
SQL> declare
2 type ri is table of rowid;
3 rowids ri;
4 begin
5 select rowid bulk collect into rowids from brainoverflow;
6 for i in rowids.first .. rowids.last loop
7 execute immediate ('delete brainoverflow where rowid='''||rowids(i)||'''');
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> select count(*) from brainoverflow;
COUNT(*)
----------
0
SQL>