ora-04091 table is Mutating-

后端 未结 2 529
灰色年华
灰色年华 2021-01-27 06:50

I\'m using a function which compares all the columns in Table 1 and Table 2 and returns \'Y\' or \'N\'. Based on that, I will update my Table 1.

But when I run the merge

2条回答
  •  长发绾君心
    2021-01-27 07:44

    You might consider using a temporary table, I.E.:

    create global temporary table table12_gt(empname varchar2(30), is_changed char(1));
    
    CREATE OR REPLACE PROCEDURE updatetabble1_2 AS
      BEGIN
       insert into table12_gt
        select empname,
               CASE
                 WHEN count(v) > 1 THEN
                  'Y'
                 ELSE
                  'N'
               END is_changed
          from (SELECT empname, trim(column1 || column2 || column3) v
                  FROM table1
                UNION
                SELECT empname, trim(column1 || column2 || column3) v FROM table2)
         GROUP BY empname;
    
      MERGE INTO Table1 DBC
      USING (SELECT empname, is_changed as DATA_CHANGED FROM table12_gt) TBL_MAIN
      ON (DBC.empname = TBL_MAIN.empname)
      WHEN MATCHED THEN
        UPDATE SET DBC.DATA_CHANGED = TBL_MAIN.DATA_CHANGED;
    
      COMMIT;
    END updatetabble1_2;
    

    This quite "quick and dirty" but can be a start

提交回复
热议问题