想要更新表格加入oracle显示错误

时间:2017-03-01 06:26:22

标签: sql database oracle plsql

使用合并更新更新表格显示错误请建议

 merge into IP_CO_WR2_USR.customer_tranching_data trn 
 using
 (Select distinct( trnx.cdb) , mig.EFFECTIVE_DATE EFFECTIVE_DATE 
  from SCVSTAGE.account_migration mig,
  SCVSTAGE.customer_details dtls, 
  IP_CO_WR2_USR.customer_tranching_data trnx
  where mig.EFFECTIVE_DATE <='13-MAR-17'
  and dtls.PLATFORM='SONATA' 
  and  dtls.cdb=mig.cdb_number 
  and  trnx.cdb=dtls.cdb ) x
 on (x.cdb = trn.cdb)
 when matched then 
 update 
 set trn.LAST_SENT_DATE= x.EFFECTIVE_DATE,
 trn.NEXT_DUE_DATE='07-SEP-17';

请使用单独运行建议内部子查询。

SQL Error: ORA-30926: unable to get a stable set of rows in the source tables
30926. 00000 -  "unable to get a stable set of rows in the source tables"
*Cause:    A stable set of rows could not be got because of large dml
           activity or a non-deterministic where clause.
*Action:   Remove any non-deterministic where clauses and reissue the dml.

1 个答案:

答案 0 :(得分:2)

根据我的理解,您面临的困难是在JAVA中使用该PLSQL单元。粗暴的方式,可以简化你的生活。

另外正如所解释的那样MERGE并不是所有推荐用于操作的源表。在这里,我定义了一个函数,并通过SQL查询调用它。希望这会有所帮助。

CREATE TABLE MY_DATE AS
SELECT level col1,level||'Av' col2 FROM dual CONNECT BY level < 11;

CREATE TABLE MY_DATE_backup AS
SELECT level COL1,level||'Av' COL2 FROM DUAL CONNECT BY level < 11 AND 1 = 2;

CREATE OR REPLACE
  FUNCTION BACKUP_FUNCTION
    RETURN NUMBER
  AS
    pragma AUTONOMOUS_TRANSACTION;
  BEGIN
    BEGIN
      INSERT INTO MY_DATE_BACKUP
      SELECT * FROM MY_DATE;
      DELETE MY_DATE;
      COMMIT;
      RETURN 1;
    EXCEPTION
    WHEN OTHERS THEN
      RETURN 0;
    END;
  END;

SELECT * FROM my_date;
SELECT * FROM my_date_backup;
SELECT BACKUP_FUNCTION FROM dual; -- Function Calling