Home » SQL & PL/SQL » SQL & PL/SQL » Identify invalid number in exception handler (Oracle 11g,Window 2008, using Toad )
icon5.gif  Identify invalid number in exception handler [message #606934] Thu, 30 January 2014 17:28 Go to next message
jxh461
Messages: 185
Registered: March 2005
Senior Member
I am getting the following error message when I run an insert select.

INSERT 
INTO  TABLE1
SELECT COL1,COL3,COL3,COL4,COL5,....,COL25
FROM TABLE2;

ORA-20202: (-1722) ORA-01722: invalid number 



When I run the select statement I return 1.4+ million records.
This tells me that there is a mismatch between a record.column with a column from TABLE2 .

I want to create an exception that will display the column and the value.

i.e

EXCEPTION
WHEN INVALID_NUMBER THEN
DBMS_OUTPUT.PUT_LINE(COLx,value); --??? t

Can someone show me how to do this better , if doable at all ?

Thanks in advance to responders.
Re: Identify invalid number in exception handler [message #606935 is a reply to message #606934] Thu, 30 January 2014 17:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Do you understand & realize that there really is a difference between SQL & PL/SQL?
INSERT INTO TABLE1 is a SQL statement
and
EXCEPTION is a PL/SQL statement

post the results from the following 2 SQL statements

DESC TABLE1
DESC TABLE2

which column in TABLE1 is a NUMBER & which corresponding column in TABLE2 is a VARCHAR2?
Re: Identify invalid number in exception handler [message #606936 is a reply to message #606935] Thu, 30 January 2014 19:20 Go to previous messageGo to next message
jxh461
Messages: 185
Registered: March 2005
Senior Member
BlackSwan,

I appreciate your insistence on details. Don't let it obscure the conceptual question.
I am very well aware of the difference between SQL and PL/SQL.

I am merely interested in the syntax that will display the information I need to identify
which of the 1.4+ million records is causing the error.

I also have a suspicion that the column in question will be of type NUMBER.
The thing is that someone must have entered an entity wrongly from the source data
and it is my intention to identify the data, hopefully in the DBMS_OUTPUT.PUT_LINE output.

BEGIN

EXECUTE IMMEDIATE ('truncate table TABLE1');

INSERT INTO TABLE1(COL1,COL2,COL3,COL4,COL5,....,COL25)
SELECT COL1,COL3,COL3,COL4,COL5,....,COL25
FROM TABLE2;

COMMIT;

EXCEPTION
 WHEN INVALID_NUMBER THEN
 DBMS_OUTPUT.PUT_LINE(COLx,value); --??? this is where I need help BlackSwan. 

END;


Output: ORA-20202: (-1722) ORA-01722: invalid number


Is there a better way to do it ? Can it be done ?

Please advise.
Re: Identify invalid number in exception handler [message #606937 is a reply to message #606936] Thu, 30 January 2014 19:42 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is there a better way to do it ?
do not SELECT non-numeric value prior to INSERT a NUMERIC column

>I also have a suspicion that the column in question will be of type NUMBER.
why suspect?
why not do actual datatype comparison as below

SELECT COLUMN_ID, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE1'
MINUS
SELECT COLUMN_ID, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE2'
UNION
SELECT COLUMN_ID, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE2'
MINUS
SELECT COLUMN_ID, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE1';

[Updated on: Thu, 30 January 2014 20:27]

Report message to a moderator

Re: Identify invalid number in exception handler [message #606944 is a reply to message #606934] Fri, 31 January 2014 00:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

See error_logging_clause in INSERT statement and the associated example.

Re: Identify invalid number in exception handler [message #607060 is a reply to message #606944] Sun, 02 February 2014 03:37 Go to previous messageGo to next message
shahnirav86
Messages: 13
Registered: June 2008
Location: anand,gujarat
Junior Member

you can use bulk insert for large number of data .so it is very usefull large data loading.
Re: Identify invalid number in exception handler [message #607062 is a reply to message #607060] Sun, 02 February 2014 03:46 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It is totally irrelevant to OP's question.
However, for your information, INSERT SELECT is ALWAYS faster than PL/SQL bulk INSERT.

Previous Topic: dynamic sql
Next Topic: How create the table with begin and end
Goto Forum:
  


Current Time: Sat Apr 20 01:50:19 CDT 2024