Oracle SQL Developer
Oracle SQL Developer
Oracle SQL Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Overview of Triggers9.1.1 Types of Triggers9.1.2 Naming TriggersA trigger is either a stored PL/<strong>SQL</strong> block or a PL/<strong>SQL</strong>, or C procedure associated witha table, view, schema, or the database itself. <strong>Oracle</strong> automatically executes a triggerwhen a specified event takes place, which usually is a DML statement being issuedagainst the table.You can create triggers to be fired on any of the following:■ DML statements (DELETE, INSERT, UPDATE)■■DDL statements (CREATE, ALTER, DROP)Database operations (LOGON, LOGOFF)Trigger names must be unique with respect to other triggers in the same schema.Trigger names do not need to be unique with respect to other schema objects, such astables, views, and procedures. For example, a table and a trigger can have the samename; however, to avoid confusion, this is not recommended.9.1.3 When Is the Trigger Fired?A trigger is fired based on a triggering statement, which specifies:■The <strong>SQL</strong> statement or the system event, database event, or DDL event that firesthe trigger body. The options include DELETE, INSERT, and UPDATE. One, two, orall three of these options can be included in the triggering statement specification.■ The table, view, DATABASE, or SCHEMA associated with the trigger.If a trigger contained the following statement:AFTER DELETE OR INSERT OR UPDATE ON employees ...then any of the following statements would fire the trigger:DELETE FROM employees WHERE ...;INSERT INTO employees VALUES ( ... );INSERT INTO employees SELECT ... FROM ... ;UPDATE employees SET ... ;An UPDATE statement might include a list of columns. If a triggering statementincludes a column list, the trigger is fired only when one of the specified columns isupdated. If a triggering statement omits a column list, the trigger is fired when anycolumn of the associated table is updated. A column list cannot be specified forINSERT or DELETE triggering statements.9.1.4 Controlling When a Trigger Is FiredThere are several ways to control when a trigger is fired.9.1.4.1 Firing Triggers With the BEORE and AFTER OptionsThe BEFORE or AFTER option in the CREATE TRIGGER statement specifies exactlywhen to fire the trigger body in relation to the triggering statement that is being run. Ina CREATE TRIGGER statement, the BEFORE or AFTER option is specified just before thetriggering statement.In general, you use BEFORE or AFTER triggers to achieve the following results:9-2 <strong>SQL</strong> <strong>Developer</strong> Online Help