A question that comes up fairly frequently revolves around how to see your errors when working with PL/SQL in SQL Developer.
Most folks are probably working in the worksheet – this is the default editor for your connection.
Let’s take a look at this sample program
create or replace procedure do_nothing is begin dbms_output.put(sysdate); this should probably error out, right? null; end; /
If we were to create this procedure, we would probably expect some errors. So let’s run this in the Worksheet. I’m using Ctrl+Enter to execute this single statement.
Ok, but how do I see the errors?
This is the worksheet. The commands run here will run very similar to how they would run in SQL*Plus. So knowing this, if we change-up the process a little bit, we can start to get better feedback from SQL Developer.
Add ‘show errors’ after the create or replace, and use F5 instead of Ctrl+Enter. This will run the entire script, and ask Oracle to show us any errors for the session.
You might be wondering why the line number is off. Oracle reports back a problem on line #4. If you’ll notice our program starts on SQL Developer worksheet line #2, but Oracle database only receives the actual statement, so you can do the math here to figure out the actual problem lies on line #5.
Viewing Errors in the Explorer
The current errors for the objects can also be viewed in the database explorer. Navigate to the object and open the ‘Errors’ panel.
Working in the Procedure Editor
As the name implies, the Procedure Editor is for developing and debugging your PL/SQL code. The full power of the IDE is realized here. Ok, so how do you get started with a Procedure Editor instead of a Worksheet?
In the object explorer, right-click on ‘Procedures’ and select ‘New Procedure.’ This will open a new Procedure Editor with the default procedure template code. Now when you compile, you’ll get much better error display support.
If you have a large program with several errors you can use the right gutter scroll bar area to scan for errors (denoted in red), then mouse-over to get the error message text. If you are looking at the feedback in the ‘Compiler’ panel below, you can double-click on an error message. This will move your cursor to the linenumber, curpos.
If you are working on a large script with multiple PL/SQL objects, I recommend using the Procedure Editor to perfect your procedure code, then copying that code back to your script and running that in the worksheet. Just don’t forget to add the ‘SHOW ERRORS’ line at the end.
Disclaimer: This post was written with Oracle SQL Developer v3.1.