Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

ALTER TRIGGER

ALTER TRIGGER

Purpose

Use the ALTER TRIGGER statement to enable, disable, or compile a database trigger.

Note: This statement does not change the declaration or definition of an existing trigger. To redeclare or redefine a trigger, use the CREATE TRIGGER statement with the OR REPLACE keywords.

See Also:

CREATE TRIGGER on page 15-95 for information on creating a trigger

DROP TRIGGER on page 17-13 for information on dropping a trigger

Oracle9i Database Concepts for general information on triggers

Prerequisites

The trigger must be in your own schema or you must have ALTER ANY TRIGGER system privilege.

In addition, to alter a trigger on DATABASE, you must have the ADMINISTER DATABASE TRIGGER system privilege.

See Also: CREATE TRIGGER on page 15-95 for more information on triggers based on DATABASE triggers

Syntax

alter_trigger::=

 

 

 

 

ENABLE

 

 

 

 

 

schema

.

 

DISABLE

 

 

 

 

 

 

 

 

 

 

 

ALTER

TRIGGER

 

trigger

RENAME

TO

new_name

 

;

 

 

 

 

 

 

 

 

 

 

 

 

DEBUG

REUSE

SETTINGS

 

 

 

 

COMPILE

 

 

 

 

12-2 Oracle9i SQL Reference

ALTER TRIGGER

Semantics

schema

Specify the schema containing the trigger. If you omit schema, then Oracle assumes the trigger is in your own schema.

trigger

Specify the name of the trigger to be altered.

ENABLE Clause

Specify ENABLE to enable the trigger. You can also use the ENABLE ALL TRIGGERS clause of ALTER TABLE to enable all triggers associated with a table.

See Also: ALTER TABLE on page 11-2 and "Enabling Triggers:

Example" on page 12-5

DISABLE Clause

Specify DISABLE to disable the trigger. You can also use the DISABLE ALL TRIGGERS clause of ALTER TABLE to disable all triggers associated with a table.

See Also: ALTER TABLE on page 11-2 and "Disabling Triggers:

Example" on page 12-4

RENAME Clause

Specify RENAME TO new_name to rename the trigger. Oracle renames the trigger and leaves it in the same state it was in before being renamed.

Note: When you rename a trigger, Oracle rebuilds the remembered source of the trigger in the USER_SOURCE, ALL_ SOURCE, and DBA_SOURCE data dictionary views. As a result, comments and formatting may change in the TEXT column of those views even though the trigger source did not change.

COMPILE Clause

Specify COMPILE to explicitly compile the trigger, whether it is valid or invalid. Explicit recompilation eliminates the need for implicit run-time recompilation and prevents associated run-time compilation errors and performance overhead.

SQL Statements: ALTER TRIGGER to COMMIT 12-3

ALTER TRIGGER

Oracle first recompiles objects upon which the trigger depends, if any of these objects are invalid. If Oracle recompiles the trigger successfully, then the trigger becomes valid.

During recompilation, Oracle drops all persistent compiler switch settings, retrieves them again from the session, and stores them at the end of compilation. To avoid this process, specify the REUSE SETTINGS clause.

If recompiling the trigger results in compilation errors, then Oracle returns an error and the trigger remains invalid. You can see the associated compiler error messages with the SQL*Plus command SHOW ERRORS.

DEBUG Specify DEBUG to instruct the PL/SQL compiler to generate and store the code for use by the PL/SQL debugger.

See Also:

Oracle9i Application Developer’s Guide - Fundamentals for information on debugging procedures

Oracle9i Database Concepts for information on how Oracle maintains dependencies among schema objects, including remote objects

REUSE SETTINGS Specify REUSE SETTINGS to prevent Oracle from dropping and reacquiring compiler switch settings. With this clause, Oracle preserves the existing settings and uses them for the recompilation.

If you specify both DEBUG and REUSE SETTINGS, Oracle sets the persistently stored value of the PLSQL_COMPILER_FLAGS parameter to INTERPRETED, DEBUG. No other compiler switch values are changed.

See Also: PL/SQL User’s Guide and Reference and Oracle9i Application Developer’s Guide - Fundamentals for more information on the interaction of the PLSQL_COMPILER_FLAGS parameter with the COMPILE clause

Examples

Disabling Triggers: Example The sample schema hr has a trigger named update_job_history created on the employees table. The trigger is fired whenever an UPDATE statement changes an employee’s job_id. The trigger inserts

12-4 Oracle9i SQL Reference

ALTER TRIGGER

into the job_history table a row that contains the employee’s ID, begin and end date of the last job, and the job ID and department.

When this trigger is created, Oracle enables it automatically. You can subsequently disable the trigger with the following statement:

ALTER TRIGGER update_job_history DISABLE;

When the trigger is disabled, Oracle does not fire the trigger when an UPDATE statement changes an employee’s job.

Enabling Triggers: Example After disabling the trigger, you can subsequently enable it with the following statement:

ALTER TRIGGER update_job_history ENABLE;

After you reenable the trigger, Oracle fires the trigger whenever an employee’s job changes as a result of an UPDATE statement. If an employee’s job is updated while the trigger is disabled, then Oracle does not automatically fire the trigger for this employee until another transaction changes the job_id again.

SQL Statements: ALTER TRIGGER to COMMIT 12-5

Соседние файлы в папке Oracle selected docs