1

I have a procedure in which 100 tables have to be updated one by one. All tables have the same column to be updated. For improving the performance I am trying to use Execute Immediate with FORALL but I am getting a lot of compilation errors.

Is it syntactically possible to update 100 different tables inside a FORALL statement using Execute immediate.

My code looks something like this.

Declare
  TYPE u IS TABLE OF VARCHAR2(240) INDEX BY BINARY_INTEGER;
      Table_List u;
FOR somecursor IN (SELECT variable1, variable2 FROM SomeTable) 
    LOOP 
        BEGIN 
            Table_List(1) := 'table1'; 
            Table_List(2) := 'table2'; 
            ......
            ......
            table_list(100):= 'table100';
       FORALL i IN Table_List.FIRST .. Table_List.LAST 
           EXECUTE IMMEDIATE 'UPDATE :1 SET column = :3 WHERE column = :2' 
             USING Table_List(i), somecursor.variable1, somecursor.variable2 ; 
     end loop;

I hope people can understand what I am trying to do through this code. If something is big time wrong please suggest me what exactly is the syntax and if it can be done in some other efficient way also.

Thanks a lot for all the help which comes my way.

4

2 回答 2

1

(1) 不,您不能使用绑定变量作为表名。

(2) 当您使用 EXECUTE IMMEDIATE 时,这意味着动态 SQL - 但 FORALL 要求只执行一条语句。一旦你指定了一个不同的表,你就在谈论一个不同的语句(不管表的结构是否恰好是等价的)。

您将不得不在普通的 FOR 循环中执行此操作。

于 2012-10-15T06:07:41.797 回答
0

只是猜测,但我认为您不能将绑定变量用作表名。你有没有尝试过:

EXECUTE IMMEDIATE 'UPDATE ' || Table_List(i) || ' SET column = :2 WHERE column = :3' ...
于 2012-10-14T19:40:00.713 回答