Debugging a Trigger

This example shows how to debug a trigger in dbForge Fusion for Oracle. Use provided scripts to create sample objects in your test database.

Creating a Sample Trigger

Procedure

Use the script available in How To: Debug a Stored Procedure to the procedure used in the sample below.

Trigger

Use the script below to create the IU_SCHEDULE_DETAIL trigger that generates an error message in case when Timesheetdate is not equal to the first date of a month.

CREATE OR REPLACE TRIGGER IU_SCHEDULE_DETAIL
  BEFORE INSERT
  ON SCHEDULE_DETAIL
  FOR EACH ROW
BEGIN
 
  IF (GETFIRSTDAYOFMONTH(:NEW.DATEOUT) <> :NEW.TIMESHEETDATE)
  THEN
    RAISE_APPLICATION_ERROR(-20000, '');
  END IF;
 
END;

Debugging a Trigger

To debug the Oracle trigger:

  1. In Database Explorer, choose your test database.
  2. Expand the Triggers folder, and then double-click the IU_SCHEDULE_DETAIL trigger to open it.
  3. Change the current view from Main to SQL.

Note

While opening a trigger the Main view is set as default. You are not able to insert a breakpoint in this view.

  1. Set a breakpoint for the trigger. Left-click in the gray margin next to the SET statement to set a breakpoint in the trigger. This step is obligatory: if you do not set a breakpoint in the trigger, you will skip over its code when you try to step into it.
  2. Expand the Procedures folder, and then double click the FILLSCHEDULE procedure to open it.
  3. Set a breakpoint for the stored procedure that will fire the trigger. Left-click in the gray margin next to the INSERT INTO SCHEDULE.SCHEDULE_DETAIL statement.

    Trigger Breakpoint in Procedure

  4. Click Start Debugging, and enter input parameters for the procedure.
  5. Step through the code using the StepInto Step Into button to move directly to the breakpoint. At the INSERT INTO SCHEDULE.SCHEDULE_DETAIL statement, when you click Step Into again, you will step into the trigger.

    Hitting Trigger Breakpoint

  6. Step through the trigger until you exit back to the stored procedure, and continue to the end.

    Stepping Through Trigger

Call Stack Window

There are two database objects in the Call Stack window: the IU_SCHEDULE_DETAIL trigger and the FILLSCHEDULE procedure. You may notice the yellow arrow next to the IU_SCHEDULE_DETAIL trigger which identifies the stack frame where the execution pointer is currently located.

Callstack for Trigger

You can get back to the procedure source code by double-clicking the procedure in the Call Stack window.

Yellow Green Arrow

A green arrow indicates that you have stepped back to the parent code that has called the trigger.

Green Arrow