3.11 Managing Triggers

A database trigger is a stored subprogram associated with a database table, view, or event. You can use Object Browser to create, view, edit, compile, download, drop, and disable or enable a trigger.

The trigger can be called once, for example when an event occurs, or many times, for example for each row affected by an INSERT, UPDATE, or DELETE statement.

3.11.1 Creating a Trigger

Create a trigger using Object Browser.

To create a trigger in Object Browser:

  1. In Object Browser, click the Create Database Objects menu and select Trigger.

    Tip:

    To create new objects from the Object Tree, right-click the object and select the Create option.

    The Create Trigger Wizard appears.

  2. On Create Trigger:
    1. Table - Select the table you want to create a trigger on.
    2. Trigger Name - Trigger name is automatically generated based on selected table. Modify the trigger name, if required. This name must conform to Oracle naming conventions and cannot contain spaces, or start with a number or underscore.
    3. Firing Point - Specify the firing point:
      • Before - Causes the database to fire the trigger before running the triggering event.
      • After - Causes the database to fire the trigger after running the triggering event.
  3. Click Create Trigger.

3.11.2 Viewing a Trigger

Select a trigger from the Object Tree and access tabs in the Object Detail View.

To view a trigger:

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
  2. The Object Detail View appears and displays four tabs:

    Tip:

    The Code and DDL tabs feature a fully functional Code Editor. To learn more about the Code Editor, see Code Editor in Object Browser.
    • Code - View the trigger code, or edit it manually. Available actions include:
      • Download
      • Save and Compile
      • Drop
      • Refresh
    • Errors - View errors related to the current trigger. Select the Refresh button to refresh the list of errors.
    • Object Details - View the details of the trigger. Available actions include:
      • Compile
      • Drop
      • Enable
      • Disable
      • Refresh
    • DDL - Displays the DDL necessary to re-create the trigger. Available actions include:
      • Download
      • Refresh

3.11.3 Editing a Trigger

Select a trigger from the Object Tree.

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
    The Object Detail View appears.
  2. In the Code tab, edit the code. Other edit controls include:
    • Undo
    • Redo
    • Find
    • Auto Complete

    Tip:

    To learn more about the Code Editor, see Code Editor in Object Browser.
  3. Select Save and Compile to save your changes.

3.11.4 Compiling a Trigger

Select a trigger from the Object Tree and click Save and Compile.

To compile a trigger in Object Browser:

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
    The Object Detail View appears.
  2. Compile the trigger:
    • On the Code tab, click Save and Compile.
    • On the Object Details tab, click Compile.
    If the compilation fails, an error message displays. Correct the error, and compile the trigger again.

3.11.5 Downloading a Trigger

Select a trigger from the Object Tree and click Download to save the trigger as a file.

To download a trigger as a file:

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
    The Object Details View appears.
  2. Download the trigger:
    • On the Code tab, click Download.
    • On the DDL tab, click Download.
  3. Enter a file name for the file and click Save.
    The file saves in .sql format.

3.11.6 Disabling and Enabling a Trigger

Select a trigger from the Object Tree and click Enable or Disable.

To disable and enable a trigger in Object Browser:

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
    The Object Detail View appears.
  2. On the Object Details tab, click Enable or Disable.

    Tip:

    Trigger Status, on the Object Details tab, indicates whether the trigger is currently ENABLED or DISABLED.
The Trigger Status updates.

3.11.7 Dropping a Trigger

Select a trigger from the Object Tree and click Drop.

To drop a trigger:

  1. In Object Browser, Object Tree, expand Triggers and select a trigger.
    The Object Detail View appears.
  2. Drop the trigger:
    • On the Code tab, click Drop.
    • On the Object Details tab, click Drop.
  3. Click Drop to drop the trigger.