Getting Column which caused the Exception [message #293606] |
Mon, 14 January 2008 04:26  |
vishal gupta
Messages: 111 Registered: March 2001
|
Senior Member |
|
|
Hi,
I am using Oracle 10g Rel 2 and currenly working on a project
which creates a repository and bulk inserts data into it using FORALL statment.
I am using SAVE Exceptions to save the errors in a table and then report to the user about these errors.
My question is ,can i somehow know the column which caused the exception ?
Currently ,we can save only SQLCODE and SQLERRM .
Is there any possibility that I get to know the column also which raised the exception ?
For example ,during a insert ,if column raises exception
ORA-01438: value larger than specified precision allows for this column
Is it possible for me know using some programming technique that which column raised this exception ?
Regards
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: BULK INSERT - column name [message #488693 is a reply to message #488644] |
Mon, 10 January 2011 11:04   |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Without the save exceptions, you get the column name, actual size, and maximum allowable size. With the save exceptions, you do not. This is documented behavior. With the save exceptions, it uses the error code to retrieve the error message, but this cannot retrieve the values. Of course, without the save exceptions, processing stops at the first error. Please see the demo below, first without then with the save exceptions.
-- test environment:
SCOTT@orcl_11gR2> SELECT * FROM v$version
2 /
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
5 rows selected.
SCOTT@orcl_11gR2> CREATE TABLE emp_temp AS
2 SELECT deptno, job
3 FROM EMP
4 WHERE 1 = 2
5 /
Table created.
SCOTT@orcl_11gR2> DESC emp_temp
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NUMBER(2)
JOB VARCHAR2(9)
-- without save exceptions:
SCOTT@orcl_11gR2> DECLARE
2 TYPE emp_rec IS RECORD
3 (deptno emp.deptno%TYPE,
4 job emp.job%TYPE);
5 TYPE emp_tab IS TABLE OF emp_rec;
6 emps emp_tab;
7 e_too_big EXCEPTION;
8 PRAGMA EXCEPTION_INIT (e_too_big, -12899);
9 BEGIN
10 SELECT deptno, job
11 BULK COLLECT
12 INTO emps
13 FROM emp
14 WHERE deptno = 10;
15 FORALL i IN 1 .. emps.COUNT
16 INSERT INTO emp_temp VALUES
17 (emps(i).deptno, emps(i).job || 'S');
18 EXCEPTION
19 WHEN e_too_big THEN
20 DBMS_OUTPUT.PUT_LINE (SQLERRM);
21 END;
22 /
ORA-12899: value too large for column "SCOTT"."EMP_TEMP"."JOB" (actual: 10,
maximum: 9)
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT * FROM emp_temp
2 /
DEPTNO JOB
---------- ---------
10 MANAGERS
1 row selected.
SCOTT@orcl_11gR2> TRUNCATE TABLE emp_temp
2 /
Table truncated.
-- with save exceptions:
SCOTT@orcl_11gR2> DECLARE
2 TYPE emp_rec IS RECORD
3 (deptno emp.deptno%TYPE,
4 job emp.job%TYPE);
5 TYPE emp_tab IS TABLE OF emp_rec;
6 emps emp_tab;
7 save_attr_except EXCEPTION;
8 PRAGMA EXCEPTION_INIT (save_attr_except, -24381);
9 errors NUMBER;
10 l_iteration VARCHAR2(100);
11 BEGIN
12 SELECT deptno, job
13 BULK COLLECT
14 INTO emps
15 FROM emp
16 WHERE deptno = 10;
17 FORALL i IN 1 .. emps.COUNT SAVE EXCEPTIONS
18 INSERT INTO emp_temp VALUES
19 (emps(i).deptno, emps(i).job || 'S');
20 EXCEPTION
21 WHEN save_attr_except THEN
22 errors := SQL%BULK_EXCEPTIONS.COUNT;
23 FOR k IN 1 .. errors LOOP
24 l_iteration := SQL%BULK_EXCEPTIONS(k).ERROR_INDEX;
25 dbms_output.put_line(
26 'Error: ' ||
27 SQLERRM(-sql%BULK_EXCEPTIONS(k).ERROR_CODE) ||
28 ' -> ' || DBMS_UTILITY.format_error_backtrace);
29 END LOOP;
30 END;
31 /
Error: ORA-12899: value too large for column (actual: , maximum: ) ->
ORA-06512: at line 17
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT * FROM emp_temp
2 /
DEPTNO JOB
---------- ---------
10 MANAGERS
10 CLERKS
2 rows selected.
SCOTT@orcl_11gR2>
[Updated on: Fri, 21 January 2011 09:23] Report message to a moderator
|
|
|
|