Home Database Mysql Tutorial insert into select 批量加载出错解决方案

insert into select 批量加载出错解决方案

Jun 07, 2016 pm 05:23 PM

当使用insert into select 批量加载数据的时候,可能会碰到因为某些数据不符合加载条件,而导致整个insert 语句无法执行,全部ro

当使用insert into select 批量加载数据的时候,可能会碰到因为某些数据不符合加载条件,而导致整个insert 语句无法执行,全部rollback。这时可以使用DML 错误日志的特性,解决这个问题。

只需要创建一个日志表,并且在使用dml语句的时候添加dml error logging 语句,即可将错误的rows记录到日志表中,而且不会影响已经加载到表中的数据。最后修正这些无法加载的数据。

操作步骤如下:

1.    创建一个日志表

可以使用DBMS_ERRLOG包创建,或者手动的创建日志表。如果使用dbms_errlog.create_error_log来创建日志表,默认的会将源表的所有列都加入需要记录的行列中。

2.    执行insert ,并且添加error logging 语句。

3.    最后查询日志表,修改无法加载的数据。

以下是一个insert into select 批量加载的例子:

第一步创建日志表

创建测试表target_t

create table target_t (id number(4),namevarchar2(2000)) ; 

创建源表source_t

create table source_t as select level as id ,'name' || level as name from dual connect by level

使用存储过程创建error logging table target_err_t

使用DBMS_ERRLOG.CREATE_ERROR_LOG会自动补全表中的所有列到日志表中。(这里表名竟然不区分大小写,,看来OracleDabase在向好的方向发展了)

EXECUTE DBMS_ERRLOG.CREATE_ERROR_LOG(dml_table_name => 'target_t',err_log_table_name=> 'target_err_log') ; 

查看一下表结构

dexter@ORCL> desc target_err_log ; 
 Name                                                Null?    Type 
 ------------------------------------------------------------- ------------------------------------ 
 ORA_ERR_NUMBER$                                              NUMBER 
 ORA_ERR_MESG$                                                  VARCHAR2(2000) 
 ORA_ERR_ROWID$                                                ROWID 
 ORA_ERR_OPTYP$                                                VARCHAR2(2) 
 ORA_ERR_TAG$                                                  VARCHAR2(2000) 
 ID                                                            VARCHAR2(4000) 
 NAME                                                          VARCHAR2(4000) 

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Reduce the use of MySQL memory in Docker Reduce the use of MySQL memory in Docker Mar 04, 2025 pm 03:52 PM

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library How to solve the problem of mysql cannot open shared library Mar 04, 2025 pm 04:01 PM

How to solve the problem of mysql cannot open shared library

What is SQLite? Comprehensive overview What is SQLite? Comprehensive overview Mar 04, 2025 pm 03:55 PM

What is SQLite? Comprehensive overview

Run MySQl in Linux (with/without podman container with phpmyadmin) Run MySQl in Linux (with/without podman container with phpmyadmin) Mar 04, 2025 pm 03:54 PM

Run MySQl in Linux (with/without podman container with phpmyadmin)

Running multiple MySQL versions on MacOS: A step-by-step guide Running multiple MySQL versions on MacOS: A step-by-step guide Mar 04, 2025 pm 03:49 PM

Running multiple MySQL versions on MacOS: A step-by-step guide

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

How do I configure SSL/TLS encryption for MySQL connections?

See all articles