Continuing Inserts in Oracle when exception is raised(引发异常时在 Oracle 中继续插入)
问题描述
我正在将数据从旧系统迁移到我们的新应用程序(在 Oracle 数据库 10gR2 上运行).作为迁移的一部分,我正在编写一个脚本,该脚本将数据插入到应用程序使用的表中.
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 the data into tables that are used by the app.
导入的数据行数达到数千,源数据不干净(NOT NULL 列中出现意外的空值等).所以在通过脚本插入数据的时候,每当发生这样的异常时,脚本会突然结束,整个事务被回滚.
The number of rows of data that are imported runs into thousands, and the source data is not clean (unexpected nulls in NOT NULL columns, etc). So while inserting data through the scripts, whenever such an exception occurs, the script ends abruptly, and the whole transaction is rolled back.
有没有办法可以继续插入行干净的数据?使用 NVL() 或 COALESCE() 不是一种选择,因为我想记录导致错误的行,以便可以在下一次通过时更正数据.
Is there a way, by which I can continue inserts of data for which the rows are clean?
Using NVL() or COALESCE() is not an option, as I'd like to log the rows causing the errors so that the data can be corrected for the next pass.
我当前的过程有一个异常处理程序,我正在记录导致错误的第一行.插入是否可以继续而不终止,因为现在在第一个处理的异常处,过程终止执行.
My current procedure has an exception handler, I am logging the first row which causes the error. Would it be possible for inserts to continue without termination, because right now on the first handled exception, the procedure terminates execution.
推荐答案
使用 PLSQL,您可以在其自己的事务中执行每个插入(在每个之后提交),并使用持续运行的异常处理程序记录或忽略错误.
Using PLSQL you can perform each insert in its own transaction (COMMIT after each) and log or ignore errors with an exception handler that keeps going.
这篇关于引发异常时在 Oracle 中继续插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:引发异常时在 Oracle 中继续插入
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
