Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the error causing ora-06575?

Recently I had to write an oracle function, and the error ora-06575 popped up awfully a lot. Usually it was because of missing colon from assignment, such as: z = 5 (vs. z := 5) Or a missed ';' at the end of a statement.

Anyway, I was able to create the function, but it failed during execution with that error, and gave no hint as to where the problem was (except that it was in the function).

I wrote same function in MSSQL and Sybase, and both of those actually tried to point me to the place of any errors. So I figure I'm doing something wrong in Oracle - it can't just tell me 'there's an error'.

In oracle I have a statement like this:

CREATE OR REPLACE
  FUNCTION...

I'm compiling the function from SQL developer by selecting the function, and pressing F9. When I select a statement which executes the function, and press F9, I get the ora-06575 error.

If I press F5 to compile the function, it tells me:

ORA-24344: success with compilation error

  Compiled.

So I found this website: http://www.dba-oracle.com/t_ora_24344_success_with_compilation_error.htm But I can't seem to run 'show errors'. When I run it, I get no output that I can see.

Can that only work from sqlplus? I'm using SQL developer, I'd prefer to stick to SQL developer. Is there something I'm missing? I want it to tell me where the error is.

like image 872
Alex Avatar asked Dec 10 '22 01:12

Alex


2 Answers

SHOW ERRORS is a sql*plus command
You can also query the USER_ERRORS view

SELECT line, position, text
FROM user_errors
WHERE name = '<<your_object_name>>'
like image 121
A.B.Cade Avatar answered Dec 28 '22 06:12

A.B.Cade


SHOW ERRORS works in SQL*Developer too (at least in the versions I've used recently, certainly 3.1). You mentioned in a comment that you're connected as SYS, so I really hope you're creating your function explicitly in another schema - I'd avoid this anyway just in case you forget one day, and modifying any of the pre-built schemas (SYS, SYSTEM etc.) is a bad idea. If so you need to prefix the errored object with the schema too:

create or replace function my_schema.x return number is
begin
    return sysdate;
end;
/
show errors my_schema.x

When run as a script (F5) this says:

FUNCTION X compiled
Warning: execution completed with warning
3/8    PLS-00382: expression is of wrong type
3/1    PL/SQL: Statement ignored

The first two lines of the output come from the function compilation, the last two from show errors. You can also run the two statements separately with F9 to see the same results.

But I'm not sure how you're getting the ORA-24344, so maybe you're on an earlier version; and it's possible that won't work. A.B.Cade's solution will work whatever your client though.

like image 26
Alex Poole Avatar answered Dec 28 '22 06:12

Alex Poole