Continuing Inserts in Oracle when exception is raised

后端 未结 5 678
滥情空心
滥情空心 2020-12-11 09:39

I\'m working on migration of data from a legacy system into our new app(running on Oracle Database, 10gR2). As part of the migration, I\'m working on a script which inserts

5条回答
  •  有刺的猬
    2020-12-11 10:01

    If the data volumes were higher, row-by-row processing in PL/SQL would probably be too slow. In those circumstances, you can use DML error logging, described here

    CREATE TABLE raises (emp_id NUMBER, sal NUMBER 
       CONSTRAINT check_sal CHECK(sal > 8000));
    
    EXECUTE DBMS_ERRLOG.CREATE_ERROR_LOG('raises', 'errlog');
    
    INSERT INTO raises
       SELECT employee_id, salary*1.1 FROM employees
       WHERE commission_pct > .2
       LOG ERRORS INTO errlog ('my_bad') REJECT LIMIT 10;
    
    SELECT ORA_ERR_MESG$, ORA_ERR_TAG$, emp_id, sal FROM errlog;
    
    ORA_ERR_MESG$               ORA_ERR_TAG$         EMP_ID SAL
    --------------------------- -------------------- ------ -------
    ORA-02290: check constraint my_bad               161    7700
     (HR.SYS_C004266) violated
    

提交回复
热议问题