Re: Intermittent ORA-01722 "invalid number"

From: Mark D Powell <>
Date: Thu, 14 Mar 2013 10:21:49 -0700 (PDT)
Message-ID: <>

On Wednesday, March 13, 2013 8:25:10 PM UTC-4, vsevolod afanassiev wrote:
> We started getting intermittent ORA-01722 "invalid number" in Oracle on AIX. According to the application logs the error comes from PL/SQL stored procedure, error message includes line number. However this stored procedure has been created in 2008 and hasn't been changed since then. It has only one IN parameter: OrderNo (order number). Users are telling us that the error is intermittent - they get it for certain order number and when they re-try later for the same order it works. I wasn't able to re-produce the error by running this stored procedure from a loop for all possible values of OrderNo. The SQL that generates error is PROCEDURE PROCESS_ORDERS IS (OrderNo IN NUMBER, ...) ORDER_TYPE NUMBER(2); BEGIN SELECT NVL(MAX(ORDER_TYPE),0) INTO ORDER_TYPE <-- This line generates error FROM ORDERS WHERE ORDER_NO = OrderNo; Column ORDER_TYPE has type NUMBER(2). Obviously declaring local variable with the same name as table column isn't very good programming practice and we will be changing this stored procedure. While this syntax is confusing it is still valid from Oracle perspective, the stored procedure is in VALID state and it works most of the time. In this database we have trigger on servererror, this trigger records all occurrences of all errors and stores them in a table. The table shows that we had 20 - 30 occurrences of ORA-01722 per day until last week when out of the blue it went to 4,000 - 5,000 per day. The number went down on weekend (as expected) and it was low on Monday, but on Tuesday and Wednesday we started getting them again, although number per 24 hours was around 1,000. We tried to enable event 1722 (alter system set events = '1722 trace name errorstack level 3'). I tested it by running SELECT TO_NUMBER('123ABC') FROM DUAL; It generated ORA-01722 and trace file was produces, it contained SQL statement I was executing in 'name=SELECT..' line. However no trace files were generated when this error occurred in the application, so there is nothing to send to Oracle to analyze. I searched metalink and found a reference to a bug in 9.2 that may cause ORA-01722. However this bug should affect only INSERT ... SELECT, not normal SELECT.

vsevolod, I would modify the code immediately to make sure the issue is not related to pl/sql scoping rules. Prefix the pl/sql variable witl v_ or l_ and label the table as in "orders o" then prefix the table columns in the select.

HTH -- Mark D Powell -- Received on Thu Mar 14 2013 - 18:21:49 CET

Original text of this message