« Wirthless Expelled ReviewStein's "Just An Opinion" On Science »

ORA-06575: Package or function X is in an invalid state

04/30/08

  03:08:17 pm, by Nimble   , 268 words  
Categories: Thoughts, Programming

ORA-06575: Package or function X is in an invalid state

If you go throw a function into Oracle, and it's wrong, e.g.

CREATE OR REPLACE FUNCTION Banana IS -- Oops, no return!
BEGIN
RETURN SUBSTUR('Banana',2,5); -- Oops, misspelled!
END;

You will get no warnings about this in most tools until it comes time to call it:

SELECT Banana FROM DUAL;

(If Banana were a procedure, we would use CALL Banana; instead)

You will get the error ORA-06575: Package or function BANANA is in an invalid state.

So how do you find out what's wrong? SHOW ERRORS; only works for SQL statements, not the contents of a stored procedure.

This is what you have to do:
SELECT * FROM USER_ERRORS WHERE NAME='BANANA' ORDER BY SEQUENCE, LINE;

It is important to put the name in uppercase.

You get:

BANANA, FUNCTION, 1, 1, 17, PLS-00103: Encountered the symbol "IS" when expecting one of the following: ( return compress compiled wrapped, ERROR, 103

If we add in the RETURN VARCHAR2 before the IS, and select the user errors again, we get:

BANANA, FUNCTION, 1, 3, 10, PLS-00201: PLS-00201: identifier 'SUBSTUR' must be declared, ERROR, 201
BANANA, FUNCTION, 2, 3, 3, PL/SQL: Statement ignored, ERROR, 0

Nice, rich error messages, but what a way to have to get them!

If you are using PL/SQL Developer, take a look under Functions or Procedures. Any stored procedures in error show up with a little X on their icon. The errors will show up if you right click->Edit. Creating the stored procedures from right-click->New on these items will save you a lot of hassle.

If you are stuck with a bit of a "manual" tool, however, the USER_ERRORS technique is your best bet.

3 comments

Comment from: Patrick [Visitor]
Patrick

Thank you very much for this gem!

01/22/09 @ 06:05
Comment from: Prakash [Visitor]
Prakash

Thanks for this.

02/09/12 @ 12:39
Comment from: Bruno Ferreira [Visitor]
Bruno Ferreira

Thak you!

01/18/17 @ 06:06
March 2019
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Ritchie Annand's blog of everything except sports (...and who knows? I may break that rule some day)

Search

  XML Feeds

powered by b2evolution free blog software