Q: | |
16-1. | A trigger is a block of code (whether in PL/SQL, Java, or C) that fires, or executes, in response to a specific event. |
Q: | |
16-2. | The statements are: True. You can create a trigger in response to most Data Manipulation Language (DML) operations. False. There is no AFTER EXECUTION. True. Oracle8i allows you to trap “user-level” events such as logons. True. Oracle8i allows you to create triggers that fire when Data Definition Language (DDL) statements are executed.
|
Q: | |
16-3. | A trigger executes implicitly in response to an event, such as an update to a table. A procedure executes explicitly at the request of a user (or a call from another program). |
Q: | |
16-4. | A trigger can have one of two modes: ENABLED (meaning that it fires normally) and DISABLED (meaning that it does not fire, even if its triggering event occurs). |
Q: | |
16-5. | (b). A trigger that causes other triggers to fire is called a cascade. |
Q: | |
16-6. | Statement-level triggers fire only one time per statement, and row-level triggers fire for each row that is affected by the DML statement. |
Q: | |
16-7. | The WHEN clause causes a trigger to fire only when a specific set of user-defined conditions are met. |
Q: | |
16-8. | Trigger (b) correctly populates the employee_id column. Trigger (a), which attempts to set the sequence number using an INSERT statement, illustrates a fairly common mistake. While Trigger (a) compiles successfully, it will probably produce the following error when it’s executed: ORA-00036: Maximum number of recursive sql levels (50) This error is generated because each execution of the trigger results in another execution of the same trigger, eventually exceeding the number of allowed recursive SQL levels. This limit was introduced to prevent such mistaken constructions from resulting in an infinite loop. |
Q: | |
16-9. | The pseudo-columns shown are: Valid Invalid Invalid Valid Valid Invalid Invalid
The OLD, NEW, and PARENT pseudo-columns can be used only in row-level triggers. PARENT, introduced in Oracle8i, refers to the current row of the parent table for a trigger defined on a nested table. OLD and NEW refer to the following: Old and new values of the current row of the relational table. Old and new values of the row of the nested table if the trigger is defined on a nested table (Oracle8i). For a trigger defined on an object table or view, OLD and NEW always refer to the object instances.
TipOLD and NEW are the default names; specifying the REFERENCING clause of the trigger can change these names. |
Q: | |
16-10. | You must have one of the following privileges: - CREATE TRIGGER
Allows you to create a trigger in your own schema for a table or view owned by the same schema - CREATE ANY TRIGGER
Allows you to create a trigger in any user’s schema on a table owned by any schema - ADMINISTER DATABASE TRIGGER
Allows you to create database-level triggers (e.g., SERVERERROR, LOGON, LOGOFF, etc.)
|
Q: | |
16-11. | The ALTER ANY TRIGGER privilege allows you only to enable/disable a trigger. The CREATE ANY TRIGGER privilege allows you to create a new trigger in any schema or recreate an existing trigger without having to explicitly drop it and then create it again. When a trigger is created, it is compiled and stored in the database. If you want to change the text of the trigger, you cannot just “edit” a piece of code; you have to change the definition in the database. To do this, you have to either use the DROP TRIGGER and CREATE TRIGGER commands or the CREATE OR REPLACE TRIGGER command. |
Q: | |
16-12. | The error occurs in the WHEN clause; when referring to the new or old values in a WHEN clause, you must omit the colon: CREATE OR REPLACE TRIGGER emp_before_ins_t
BEFORE INSERT
ON employee
FOR EACH ROW
WHEN (NEW.mgr is null)
BEGIN
IF (:NEW.sal > 800)
THEN
:NEW.sal := 850;
END IF;
END; Also, note that the WHEN condition must be a SQL condition, rather than a PL/SQL condition. PL/SQL functions or methods cannot be invoked from the trigger WHEN clause. |
Q: | |
16-13. | When Oracle compiles the trigger definition, it parses the entire code and reports all the errors encountered during the compilation phase; you can see these errors by querying the trusty USER_ERRORS data dictionary view: SELECT line, position, text
FROM user_errors
WHERE name = 'MY_TRIGGER'
AND TYPE = 'TRIGGER'
ORDER BY sequence In SQL*Plus, you can also use the following shortcut: SQL> SHOW ERRORS TRIGGER MY_TRIGGER WarningRemember that if a trigger compiles with errors, it still gets created but fails during the execution. This means that all triggering DML statements are blocked until the trigger is temporarily disabled, dropped, or replaced with the trigger version that compiles without errors. |
Q: | |
16-14. | There is only one way to explicitly recompile a trigger: execute the ALTER command with the COMPILE option: ALTER TRIGGER my_trigger_name COMPILE You might have to use this command because triggers, as part of the Oracle object dependency, may become invalid if an object that the trigger depends upon changes. |
Q: | |
16-15. | You might want to omit the OR REPLACE option when you first create a trigger to save yourself a headache if a trigger by that name already exists in that schema. Since you’re not using the OR REPLACE option, if a trigger already exists by that name, you get the following error: ORA-04081: trigger name already exists |
Q: | |
16-16. | The statements are: Incorrect. Oracle explicitly prohibits developers from putting triggers on SYS data dictionary objects, because this could inadvertently modify the behavior of the database. If an attempt is made to create a trigger on a SYS object, Oracle generates the error: ORA-04089: cannot create triggers on objects owned by SYS Correct. See (a). Incorrect. Prior to Oracle8i, DML events were the only events that could be trapped by triggers. Oracle8i introduced the ability to trap other events as well, such as database-level events (STARTUP, SHUTDOWN, etc.) and DDL events (CREATE, DROP, etc.).
|
Q: | |
16-17. | The statements are: False. You can create triggers only for certain types of schema objects. True. Oracle7 allowed the triggers to be created at the TABLE level. True. Oracle8 added the ability to define triggers for VIEWs, which opened the road to fully updateable views in Oracle. True. Oracle8i introduced the triggers created on NESTED TABLE level. True. As of Oracle8i, you can also use the ON clause to define triggers for database or schema-level events. The DATABASE keyword specifies that the trigger is defined for the entire database, and the SCHEMA keyword specifies that the trigger is defined for the current schema.
|
Q: | |
16-18. | (c). Here is the required syntax: CREATE OR REPLACE TRIGGER upd_employee_commision
AFTER UPDATE OF comm
ON emp
FOR EACH ROW
BEGIN
<<Trigger logic>>
END; |
Q: | |
16-19. | (d). The trigger already fires just once for each INSERT operation on the emp table. |
Q: | |
16-20. | The trigger fails because the statement-level trigger cannot reference a pseudo-column name such as :NEW or :OLD. This is only available for row-level triggers. |
Q: | |
16-21. | A mutating table is a table that is currently being modified by an UPDATE, DELETE, or INSERT statement, or it is a table that might need to be updated by the effects of a declarative DELETE CASCADE referential integrity constraint. The SQL statements of a trigger cannot read from (query) or modify a mutating table of the triggering statement. |