Thanks for the question, Anand.
Asked: November 24, 2015 - 7:09 am UTC
Last updated: November 27, 2015 - 2:38 am UTC
Version: Oracle 11g
Viewed 10K+ times! This question is
You Asked
Hi,
I am facing an issue to get rejected records while using direct insert/update/merge in my PL/SQL code.
Please find my code below:
PROCEDURE TMP_PROC_INSERT_1 AS
BEGIN
TMP_EXEC_LOG('TMP_PROC_INSERT_1', 'I', SYSDATE, 'OK'); --This procedure will track TMP_PROC_INSERT_1 execution details
EXECUTE IMMEDIATE 'TRUNCATE TABLE TMP_TARGET_TABLE_1 DROP STORAGE';
INSERT INTO TMP_TARGET_TABLE_1
(
EMP_ID,
EMP_NAME
)
SELECT
EMP_ID,
EMP_NAME
FROM
TMP_SOURCE_TABLE_1;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
TMP_EXEC_LOG('TMP_PROC_INSERT_2','U',SYSDATE,'KO');
TMP_ERROR_TABLE('TMP_TARGET_TABLE_1',SQLERRM,SQLCODE,SYSDATE,user); --This procedure will track TMP_PROC_INSERT_1 error details.
END TMP_PROC_INSERT_1;
Requirements:
1.We need to load our target table via DIRECT INSERT.
2.If any rows got rejected then we should keep those rejected row in another table(log table) .
3.And also we need to track the EXECUTION & ERROR details.
Ways we tried :
1.We tried DBMS_ERRLOG.create_error_log to overcome this issue.
-> This option helped us to take backup of REJECTED ROWS
-> But it failed to track EXECUTION & ERROR details(because it skips EXCEPTION block)
Please help me overcome this issue.
and Chris said...
Log errors records the exception directly in the err$_log table, so you can read these from there. Error logging also lets you specify a tag for the exceptions. You can pass a string of the date + user to help you identify when the errors happened.
create table t (
x varchar2(3)
);
begin
DBMS_ERRLOG.create_error_log (dml_table_name => 't');
end;
/
insert into t
select lpad('x', level, 'x') from dual
connect by level <= 5
log errors into err$_t (to_char(sysdate, 'dd/mm/yyyy hh24:mi') || '-' || user)
reject limit unlimited;
select x, ora_err_mesg$, ora_err_tag$
from err$_t;
X ORA_ERR_MESG$ ORA_ERR_TAG$
----- -------------------------------------------------------------------------------- -------------------------
xxxx ORA-12899: value too large for column "CHRIS"."T"."X" (actual: 4, maximum: 3) 24/11/2015 10:30-CHRIS
xxxxx ORA-12899: value too large for column "CHRIS"."T"."X" (actual: 5, maximum: 3) 24/11/2015 10:30-CHRIS
Rating
(2 ratings)
Is this answer out of date? If it is, please let us know via a Comment