Basic PL/SQL Debugging Tips using Oracle SQL Developer - Oracle
Oracle is one of the most important relational database implemented both in big and small corporations. This is a beginner tutorial that will walk you through common debugging techniques and tips in Oracle using SQL Developer.
Launch Oracle SQL developer by going to Applications – Programming – SQL Developer. If it asks for a JDK path, simply type the path you obtained in the previous section, then press enter (e.g.: /usr/lib/jvm/java-6-openjdk).
The SQL Developer will then load.
Go to Application – Oracle Database 10G Express Edition – click “Go to Database Homepage”.
Login as database administrator.
Click “Administration”.
Click “Database users”. You should see a user named HR with a lock icon on it. This means you cannot use the HR user, you need to unlock it first.
Click the “Home” link and in home, click “SQL”.
Click SQL commands.
Type this command in the textbox:
alter user hr identified by hr account unlock;
Click “Run”. Assign “HR” the necessary debugging privileges (enter them one at a time at SQL commands text box and click run)
grant DEBUG ANY PROCEDURE to HR; grant DEBUG CONNECT SESSION to HR;
In Oracle SQL Developer. Go to File – New – and select “Database Connection”. Click OK. Enter the following information:
Click Test, it should not return any errors. If there are no errors, click “Connect”.
Expand “debugging_example”. And then expand “Procedures”. Click “ADD_JOB_HISTORY”. Let's start with the most basic debugging example by simulating an error. Go to the next section.
Using the Oracle SQL Developer Debugger
In the ADD_JOB_HISTORY. Click the red bug icon (which is the debugger icon). You can locate this beside “Run”. See screenshot below:
Copy the code below and overwrite the existing procedure:
Now click OK. An error will show, such as : “PLS-00201: Identifier 'LL' must be declared.” It is located in Line 12. Click OK.
Now to correct the error, change:
P_DEPARTMENT_ID := LL;
To simply:
P_DEPARTMENT_ID := NULL;
Click OK again. It will execute the debugger and then halt in this line:
INSERT INTO job_history (employee_id, start_date, end_date, job_id, department_id)
To continue; press F7 (for Step into). You will then see the result of the debugging process as follows:
Connecting to the database debugging_example. Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', '36477' ) Debugger accepted connection from database on port 36477. Exception breakpoint occurred at line 11 of ADD_JOB_HISTORY.pls. $Oracle.EXCEPTION_ORA_1400: ORA-01400: cannot insert NULL into ("HR"."JOB_HISTORY"."EMPLOYEE_ID") ORA-06512: at "HR.ADD_JOB_HISTORY", line 10 ORA-06512: at line 14 Executing PL/SQL: CALL DBMS_DEBUG_JDWP.DISCONNECT() Process exited. Disconnecting from the database debugging_example. Debugger disconnected from database.
In some instances you can test values to be used during the debugging process. To do this, click the “Data” tab (shown below). Change “null” to any data that can be assigned to the field as that field cannot be null. You can change the value by double clicking “Null”. See screenshot:
For example a fictitious value 3621 is assigned to employee ID.