简体   繁体   English

如何在更新时捕获失败的记录并继续使用Oracle中的其余记录?

[英]How to capture the failed records while updating and continue with the rest in Oracle?

I have a table with 50k records. 我有一张有5万条记录的桌子。 How to capture the failed records(primary key) while updating and continue with the rest? 如何在更新时捕获失败的记录(主键)并继续进行其余操作?

Create table temp(
  id       NUMBER,
  word     VARCHAR2(1000),
  Sentence VARCHAR2(2000),
  valid    NUMBER
);

insert into temp
SELECT 1,'automation testing', 'automtestingation testing is popular kind of testing',0 FROM DUAL UNION ALL
SELECT 2,'testing','manual testing',0 FROM DUAL UNION ALL
SELECT 3,'manual testing','this is an old method of testing',0 FROM DUAL UNION ALL
SELECT 4,'punctuation','automation testing,manual testing,punctuation,automanual testing-testing',0 FROM DUAL UNION ALL
SELECT 5,'B-number analysis','B-number analysis table' FROM DUAL UNION ALL
SELECT 6,'B-number analysis table','testing B-number analysis',0 FROM DUAL;

update temp set valid = 1;

I am expecting to capture all the failed records, that is records which failed while updating to valid =1 . 我希望捕获所有失败的记录,即在更新为valid =1时失败的记录。 I want to capture the primary key of all the records that failed to update and the update should continue. 我想捕获所有未能更新的记录的主键,并且更新应该继续。

I want to capture the primary key of all the records that failed to update and the update should continue. 我想捕获所有未能更新的记录的主键,并且更新应该继续。

UPDATE is a single statement. UPDATE是单个语句。 Single statements either succeed or fail in their entirety . 单个语句整体上成功或失败。 Consequently for the given example all records are successful or they are all failed. 因此,对于给定的示例,所有记录均成功或全部失败。

However, for Bulk Operations such as ETL Oracle does provide a DML Logging capability. 但是,对于ETL等批量操作,Oracle确实提供了DML日志记录功能。 It is covered in the PL/SQL Reference and the Admistrator's Guide (because it requires the creation of tables to capture the errors). 它在《 PL / SQL参考》《管理员指南》中都有介绍(因为它需要创建表来捕获错误)。 Although to be honest Tim Hall's article on his Oracle Base site is probably more helpful as a place to start . 坦白说,尽管Tim Hall在其Oracle Base站点上的文章可能是一个更好的起点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM