Oracle DML容错处理(1)
Oracle dml操作过程中可能出现键重复或者数据类型不一致等问题,一般进行数据处理时候需要对这些可能出现的错误提前考虑,避免更新失败。Oralce给出了一些其他解决方案,以在不同场景下使用。
1、ignore_row_on_dupkey_index HINT
Oracle 11.2.0.1 版本中心加入的3个提示CHANGE_DUPKEY_ERROR_INDEX, IGNORE_ROW_ON_DUPKEY_INDEX, RETRY_ON_ROW_CHANGE,与其他提示不同,特别之处在于存在"语义效果(semantic effect)"。
在 insert into tablea ...select * from tbl中,如果存在唯一约束,会导致整个insert操作失败。使用IGNORE_ROW_ON_DUPKEY_INDEX提示,会忽略唯一约束冲突,回滚当前行,继续完成其他行的插入。
示例:
数据准备:
create table emp1(empno number primary key,ename varchar2(50));
insert into emp1(empno,ename) select empno,ename from emp;
commit;
emp1表存在empno主键.
再次插入:
insert into emp1(empno,ename) select empno,ename from emp;
提示错误:
ORA-00001: 违反唯一约束条件 (SCOTT.SYS_C0013035)
使用HINT:
insert /*+ignore_row_on_dupkey_index(emp1,SYS_C0013035)*/into emp1(empno,ename) select empno,ename from emp;
提示:插入0行;
SYS_C0013035:创建主键时oracle自动生成的索引。
2、使用dbms_errlog包
说明:10g后可用,不支持LONG, CLOB, BLOB, BFILE, ADT数据类型
创建错误日志表
begin
dbms_errlog.create_error_log(dml_table_name => 'EMP1',
err_log_table_name => 'T_ERR_LOG',
err_log_table_owner => user,
err_log_table_space => 'users',
skip_unsupported => true);
end;
参数说明:
|
Parameter |
Description |
|
dml_table_name |
The name of the DML table to base the error logging table on. The name can be fully qualified (for example, emp, scott.emp, "EMP", "SCOTT"."EMP"). If a name component is enclosed in double quotes, it will not be upper cased. |
|
err_log_table_name |
The name of the error logging table you will create. The default is the first 25 characters in the name of the DML table prefixed with'ERR$_'. Examples are the following: dml_table_name: 'EMP', err_log_table_name: 'ERR$_EMP' dml_table_name: '"Emp2"', err_log_table_name: 'ERR$_Emp2' |
|
err_log_table_owner |
The name of the owner of the error logging table. You can specify the owner indml_table_name. Otherwise, the schema of the current connected user is used. |
|
err_log_table_space |
The tablespace the error logging table will be created in. If not specified, the default tablespace for the user owning the DML error logging table will be used. |
|
skip_unsupported |
When set to TRUE, column types that are not supported by error logging will be skipped over and not added to the error logging table. When set to FALSE, an unsupported column type will cause the procedure to terminate. The default is FALSE. |
对于不支持的数据类型可以使用最后一个参数控制,如果为true,不支持类型字段将不会进入错误日志表。如果是false,在遇到不支持类型字段时执行包会报错。
各参数默认值如下:
DBMS_ERRLOG.CREATE_ERROR_LOG (
dml_table_name IN VARCHAR2,
err_log_table_name IN VARCHAR2 := NULL,
err_log_table_owner IN VARCHAR2 := NULL,
err_log_table_space IN VARCHAR2 := NULL,
skip_unsupported IN BOOLEAN := FALSE);
注意:再次执行该包会报错,执行前须确认错误记录表不存在。
dml使用错误日志表
insert into emp1(empno,ename) select empno,ename from emp log errors into t_err_log reject limit unlimited;
注意红色字体部分。Limimt后面可以是具体数字,表示容错行数
语法:
LOG ERRORS [INTO [schema.]table] [('simple_expression')] [REJECT LIMIT integer|UNLIMITED]
simple_expression:用来标记t_err_log表ora_err_tag$字段信息
Update、merge和delete也可以使用该方法。
更新完检查t_err_log失败记录及错误原因。
Oracle DML容错处理(1)的更多相关文章
- Oracle DML容错处理(2)
关于DML Error Logging效率的问题,摘自网上一篇文章,作为单独一篇说明,原文如下: DML Error Logging in Oracle 10g Database Release 2 ...
- oracle DML语句
DML语句 1. 插入数据 创建一个新表 create table new_cust as select * from customers --使用insert语句添加行 /* 确定要插入的行所在的 ...
- Oracle(DML)
数据操作语言: insert update delete 事务控制语言: commit rollback savepoint 1.insert语句 两种格式: 直接插入 子查询插入 1. 直接插入基本 ...
- oracle DML错误日志(笔记)
DML错误日志是oracle10gR2引入的一个类似于SQL*Loader的错误日志功能.它的基本原理是把任何可能导致语句失败的记录转移,放到一张错误日志表中. 具体使用如下: 1.使用DBMS_ER ...
- oracle DML(数据管理语言)sql 基本语句
- oracle DML语句 事务的定义与特点
1.insert into (插入数据) insert in to 表名(列表1,列表2) values(要插入的数据1,数据2); or insert into 表名 values(数据 ...
- 转 如何观察 undo Oracle DML语句回滚开销估算
https://searchdatabase.techtarget.com.cn/7-20392/ --use_urec 详细解读: select USED_UREC from v$transacti ...
- Oracle ddl 和 dml 操作
ddl 操作 窗口设置用户权限的方法 Oracle的数据类型 按住Ctrl点击表名 ,可以鼠标操作 插入的数据需要满足创建表的检查 主表clazz删除数据从表设置级联也会一同删除 有约束也 ...
- ORACLE 11G R2 RAC classical install OGG12.1(LINUX) 经典抽取模式单项同步配置OGG12.1
博文结构图如下: 一.环境描述以及注意事项 1.1 环境简介 IP 系统 Oracle版本 OGG版本 源端 172.16.10.16/36 RHEL6.5 oracle11204 12.1 目标端 ...
随机推荐
- 求最短路径算法之SPAF算法。
关于求最短路径: 求最短路径的算法有许多种,除了排序外,恐怕是OI界中解决同一类问题算法最多的了.最熟悉的无疑是Dijkstra(不能求又负权边的图),接着是Bellman-Ford,它们都可以求出由 ...
- SQL SERVER2005 excel float导入
接到mission:将一堆excel的东西导入到SQL SERVER2005 命令很easy SELECT * INTO XLImport3 FROM OPENDATASOURCE('Microsof ...
- jQuery Easy UI LinkButton(button)包
LinkButton(button)包,easyui其中一个基本组成部分 演示样例: <!DOCTYPE html> <html> <head> <title ...
- GridView中的编辑和删除按钮,执行更新和删除代码之前的更新提示或删除提示
在GridView中,可以通过设计界面GridViewr任务->编辑列->CommandField,很简单的添加的编辑和删除按钮 在前台源码中,可以看到GridView自动生成了两个列. ...
- 【C#版本详情回顾】C#2.0主要功能列表
泛型 优点:类型安全/重用代码/提升性能 应用:泛型接口.泛型类.泛型类型参数.泛型方法.泛型事件和泛型委托 命名空间:System.Collections.Generic 特性:泛型约束,defau ...
- 项目管理和版本跟踪——Redmine和SVN的结合
项目管理和版本跟踪——Redmine和SVN的结合 分类: Redmine2009-06-01 10:38 565人阅读 评论(0) 收藏 举报 svn项目管理tortoisesvn数据库railsr ...
- FileOutputStream字节输出流和FileInputStream输入流(切记:out是输出到本地中,in是输入到程序中)这里介绍大文件和小文件的读取方式
//FileOutputStream public class FileOutputStreamDemo { /**字节流:适用于任何文件,以字节为单位,进行读写操作 *字节流操作步骤: *1.创 ...
- 通过反射生成SQL的例子
全文摘自http://www.cnblogs.com/g1mist/p/3227290.html,很好的一个实例. 反射提供了封装程序集.模块和类型的对象.您可以使用反射动态地创建类型的实例,将类型绑 ...
- 活动图activity diagram
活动图activity diagram 系列文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend) [UML]UML系列——类 ...
- 类图class的关联关系(聚合、组合)
类图class的关联关系(聚合.组合) 关联的概念 关联用来表示两个或多个类的对象之间的结构关系,它在代码中表现为一个类以属性的形式包含对另一个类的一个或多个对象的应用. 程序演示:关联关系(code ...