-2

forExecute Immediateを使用して、 pl/sql ブロッ​​クFORALLで収集します。BULK

FORALL i in rowid.FIRST ..rowid.LAST
Execute Immediate 'Delete table_name  where rowid '=rowid(i)

上記のことは機能しません。誰でもinsertandの構文を教えてもらえますdeleteか?

4

1 に答える 1

1

これを実現する方法の例を次に示します。

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> 
于 2012-05-25T09:25:37.577 に答える