RubyMine 2019.3 Help

Debugging Oracle PL/SQL code

The debugger is based on the Oracle Probe that uses API of the DBMS_DEBUG package and should work on Oracle servers 9.0 and later.

In Oracle, you can debug the following program units (PL/SQL programs): anonymous blocks, packages, procedures, functions, and triggers.

Step 1. Create a PL/SQL object

  1. Right-click the Oracle data source and select Open Console Ctrl+Shift+F10.

  2. Type or paste your code in the console.

  3. Click the Execute button the Execute button or press Ctrl+Enter to run the procedure code.

    As a result, you see a created object in the Database tool window (View | Tool Windows | Database).

Create a PL/SQL object

Code snippet of the procedure on GitHub

Step 2. Compile a PL/SQL object with the debug option

To enable debugging for a PL/SQL code, you need to compile it with the debug option. The process of compilation converts PL/SQL code to Pro*C, which is then compiled to Oracle shared libraries. The compilation helps the Oracle interpreter to process your code faster.

  1. Right-click the PL/SQL object that you want to debug and select Database Tools | Recompile.

  2. In the Recompile dialog, select With "debug" option.

  3. Click OK.

    Compile code for debugging

Step 3. Debug PL/SQL program units

Debug PL/SQL procedures and functions through anonymous blocks

PL/SQL program units organize the code into blocks. A block without a name is an anonymous block. The anonymous block is not stored in the Oracle database. In the debugging process, you use the anonymous block to pass values for parameters.

To debug procedures and functions, write an anonymous block that calls the necessary routine.

  1. In the Database tool window (View | Tool Windows | Database), double-click the PL/SQL object that you created and compiled for debugging.

  2. Click the Run Procedure button the Run Procedure button. If the session is not selected, select a session from the drop-down list. For more information about managing sessions, see Managing connection sessions.

  3. From the Execute Routine dialog, click the Open in console icon (the Open in console icon) to open the anonymous block in the Oracle console. Alternatively, you can copy and paste the anonymous block to the console manually.

  4. Place breakpoints in the anonymous block and in the PL/SQL program object that is referenced in this anonymous block.

  5. (Optional) Modify parameter values.

  6. Click Debug.

Code snippet of the procedure on GitHub

Debug PL/SQL triggers through queries

A trigger is a PL/SQL program unit that is automatically called by the DBMS when you issue INSERT, UPDATE or DELETE queries. Triggers are associated with a table and are called before or after you insert, update, or delete a data row. A table can have several triggers.

To debug a trigger, write an INSERT, UPDATE or DELETE query to a table or a view.

  1. Right-click the Oracle data source and select Open Console Ctrl+Shift+F10.

  2. Type a query in the console.

  3. Place breakpoints in a trigger.

  4. Click Debug.

Code snippet of the trigger on GitHub

Stepping modes

When you debug PL/SQL code, you can select between two stepping modes: Graceful and Native.

In Graceful mode, you can pause the session that you debug (the target session), set and remove breakpoints. If no valid breakpoints are set, the debugger steps through code on a line-by-line basis.

In Native mode, the debugger uses Oracle native debugging commands. You cannot pause the target session or manage breakpoints but you might experience a boost in performance in CPU-intensive operations (operations that include a lot of computations and loops). You can read more about Oracle debugging commands in the official Oracle documentation. If no valid breakpoints are set, the debugger executes the whole routine.

Change the stepping mode

  1. Open settings (Ctrl+Alt+S) and navigate to Build, Execution, Deployment | Debugger | Stepping.

  2. From the Stepping mode list, select the stepping mode that you need.

Pause at the beginning of debuggable code

You can force the debugger to pause at the beginning of debuggable code. The place where the debugger pauses is detected automatically. If you assign variable values in the declaration section, the debugger pauses at the variable declaration. If no values are assigned to variables, the debugger skips the declaration section and pauses at the BEGIN keyword in the execution section.

  1. Open settings (Ctrl+Alt+S) and navigate to Build, Execution, Deployment | Debugger | Stepping.

  2. Select Pause at begin.

Pause at the beginning of debuggable code
Last modified: 5 December 2019