Examples of how to use Error Logging for SQL statements (Doc ID 1076042.1)
2013-11-23 14:22
525 查看
In this Document
Applies to:
Oracle Server - Enterprise Edition - Version 10.2.0.1 to 11.2.0.4 [Release 10.2 to 11.2]
Information in this document applies to any platform.
Goal
Give examples of the Error Logging feature for SQL introduced in 10.2
Simple case involving one table
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLE FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
-- Table created
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- PL/SQL procedure successfully completed.
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #2
Test a multi table insert with only one of the two tables using error logging but without using multitable insert statements
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLES FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
create table test2 (col1 varchar2(3) primary key, col2 varchar2(20));
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
insert into test2 values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE FIRST TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
insert into test2 values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 101
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #3
Test a multi table insert with only one of the two tables using error logging using multitable insert statements
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLES FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
create table test2 (col1 varchar2(3) primary key, col2 varchar2(20));
create table test3 (col1 number);
-- LOAD THE TEST3 TABLE WITH VALUES
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test3 values(i);
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
commit;
-- Commit complete.
insert all
into test values (to_char(col1),'test')
into test2 values (to_char(col1),'test')
select col1 from test3;
-- ERROR at line 2:
-- ORA-12899: value too large for column "TEST"."TEST"."COL1" (actual: 2, maximum:1)
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE FIRST TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
insert all
into test values (to_char(col1),'test') log errors into err$_test reject limit unlimited
into test2 values (to_char(col1),'test')
select col1 from test3;
-- 111 rows created.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 101
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
DROP TABLE TEST2 PURGE;
DROP TABLE TEST3 PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #4
Simple case involving one table but with manually created error logging table
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLE FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
-- Table created
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
-- MANUALLY CREATE THE ERROR LOGGING TABLE
CREATE TABLE ERR$_TEST
( "ORA_ERR_NUMBER$" NUMBER,
"ORA_ERR_MESG$" VARCHAR2(2000),
"ORA_ERR_ROWID$" UROWID (4000),
"ORA_ERR_OPTYP$" VARCHAR2(2),
"ORA_ERR_TAG$" VARCHAR2(2000),
"COL1" VARCHAR2(4000),
"COL2" VARCHAR2(4000)
) SEGMENT CREATION IMMEDIATE;
-- PL/SQL procedure successfully completed.
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
Applies to:
Oracle Server - Enterprise Edition - Version 10.2.0.1 to 11.2.0.4 [Release 10.2 to 11.2]
Information in this document applies to any platform.
Goal
Give examples of the Error Logging feature for SQL introduced in 10.2
Simple case involving one table
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLE FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
-- Table created
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- PL/SQL procedure successfully completed.
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #2
Test a multi table insert with only one of the two tables using error logging but without using multitable insert statements
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLES FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
create table test2 (col1 varchar2(3) primary key, col2 varchar2(20));
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
insert into test2 values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE FIRST TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
insert into test2 values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 101
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #3
Test a multi table insert with only one of the two tables using error logging using multitable insert statements
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLES FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
create table test2 (col1 varchar2(3) primary key, col2 varchar2(20));
create table test3 (col1 number);
-- LOAD THE TEST3 TABLE WITH VALUES
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test3 values(i);
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
commit;
-- Commit complete.
insert all
into test values (to_char(col1),'test')
into test2 values (to_char(col1),'test')
select col1 from test3;
-- ERROR at line 2:
-- ORA-12899: value too large for column "TEST"."TEST"."COL1" (actual: 2, maximum:1)
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 0
-- ENABLE ERROR LOGGING FOR THE FIRST TABLE
begin
dbms_errlog.create_error_log('TEST') ;
end;
/
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
insert all
into test values (to_char(col1),'test') log errors into err$_test reject limit unlimited
into test2 values (to_char(col1),'test')
select col1 from test3;
-- 111 rows created.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
select count(*) from test2;
-- COUNT(*)
-- ----------
-- 101
-- CLEAN UP FROM THE TEST
DROP TABLE TEST PURGE;
DROP TABLE ERR$_TEST PURGE;
DROP TABLE TEST2 PURGE;
DROP TABLE TEST3 PURGE;
CONNECT / AS SYSDBA
DROP USER TEST CASCADE;
CASE STUDY #4
Simple case involving one table but with manually created error logging table
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
-- CREATE THE TABLE FOR THE TEST
create table test (col1 varchar2(1) primary key, col2 varchar2(20));
-- Table created
-- PRODUCE AN ERROR
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test');
i := i+1;
end loop;
end;
/
-- ERROR at line 1:
-- ORA-12899: value too large for column "SYS"."TEST"."COL1" (actual: 2, maximum:1)
-- ORA-06512: at line 5
-- SHOW THAT NO ROWS WERE INSERTED
select count(*) from test;
-- COUNT(*)
-- ----------
-- 0
-- MANUALLY CREATE THE ERROR LOGGING TABLE
CREATE TABLE ERR$_TEST
( "ORA_ERR_NUMBER$" NUMBER,
"ORA_ERR_MESG$" VARCHAR2(2000),
"ORA_ERR_ROWID$" UROWID (4000),
"ORA_ERR_OPTYP$" VARCHAR2(2),
"ORA_ERR_TAG$" VARCHAR2(2000),
"COL1" VARCHAR2(4000),
"COL2" VARCHAR2(4000)
) SEGMENT CREATION IMMEDIATE;
-- PL/SQL procedure successfully completed.
-- RE-EXECUTE THE PROCESS THAT PRODUCED THE EARLIER ERRORS AND LOG THE ERRORS
declare i number;
begin
i := 0;
while i <= 100 loop
insert into test values (to_char(i),'test')
LOG ERRORS INTO ERR$_TEST REJECT LIMIT UNLIMITED;
i := i+1;
end loop;
end;
/
-- PL/SQL procedure successfully completed.
-- SHOW THE RESULTS
select count(*) from test;
-- COUNT(*)
-- ----------
-- 10
select count(*) from err$_test;
-- COUNT(*)
-- ----------
-- 91
-- COL1 values 0-9 succeed ... values 10-100 fail
相关文章推荐
- How to Collect and Display System Statistics (CPU and IO) for CBO use (Doc ID 149560.1)
- How To Collect 10046 Trace (SQL_TRACE) Diagnostics for Performance Issues (Doc ID 376442.1)
- How to Collect Errorstacks for use in Diagnosing Performance Issues. (文档 ID 1364257.1)
- How to Determine the Version of Oracle XML Publisher for Oracle E-Business Suite 11i and Release 12 (Doc ID 362496.1)
- OA Framework - How to Find the Correct Version of JDeveloper to Use with E-Business Suite 11i or Release 12.x (Doc ID 416708.1)
- CodeSnip: How to Get Id of the Record Using ASP.NET and SQL Server 2000
- How to determine the correct setting for JOB_QUEUE_PROCESSES (Doc ID 578831.1)
- How to Enable SQL_TRACE for Another Session or in MTS Using Oradebug(文档 ID 1058210.6)
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- (NOT CLEAR)Question 21: Which of the following statements provide a valid reason not to use RTTI for distributed (i.e. networked
- Master Note: How to Identify Resource Intensive SQL for Tuning [ID 232443.1]
- How To Use XDOLoader to Manage, Download and Upload Files? (DOC ID 469585.1)
- R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)
- How To Configure Client Failover For Dataguard Connections Using Database Services (Doc ID 1429223.1
- How to use Format Triggers in Reports (Doc ID 31364.1)
- you try to use the STM32 Library examples with IAR 6.30.6 you get a loot of error
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- Linux: How to Configure the DNS Server for 11gR2 SCAN (Doc ID 1107295.1)
- How to Identify Resource Intensive SQL ("TOP SQL") (Doc ID 232443.1)