12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Designing Triggersraising an exception. User-defined exceptions are commonly used in triggers thatenforce complex security authorizations or integrity constraints.9.2 Designing TriggersThis topic discusses the design of triggers. It includes the following topics:■Guidelines For Triggers9.2.1 Guidelines For Triggers■■Restrictions on Creating TriggersPrivileges Needed to Work with TriggersUse the following guidelines when designing your triggers:■■Use triggers to guarantee that when a specific operation is performed, relatedactions are performed.Do not define triggers that duplicate features already built into <strong>Oracle</strong> Database.For example, do not define triggers to reject bad data if you can do the samechecking through declarative integrity constraints.■ Limit the size of triggers. If the logic for your trigger requires much more than 60lines of PL/<strong>SQL</strong> code, it is better to include most of the code in a stored procedureand call the procedure from the trigger. The size of the trigger cannot be more than32K.■■■Use triggers only for centralized, global operations that should be fired for thetriggering statement, regardless of which user or database application issues thestatement.Do not create recursive triggers. For example, creating an AFTER UPDATEstatement trigger on the employees table that itself issues an UPDATE statementon employees, causes the trigger to fire recursively until it has run out ofmemory.Use triggers on DATABASE judiciously. They are executed for every user everytime the event occurs on which the trigger is created.9.2.2 Restrictions on Creating TriggersWhen creating triggers with PL/<strong>SQL</strong> code, there are some restrictions that are notrequired for standard PL/<strong>SQL</strong> blocks. The following topics discuss these restrictions.<strong>SQL</strong> Statements Allowed in Trigger BodiesThe body of a trigger can contain DML <strong>SQL</strong> statements. It can also contain SELECTstatements, but they must be SELECT... INTO... statements or the SELECT statement inthe definition of a cursor.DDL statements are not allowed in the body of a trigger. Also, no transaction controlstatements are allowed in a trigger. ROLLBACK, COMMIT, and SAVEPOINT cannot beused.For system triggers, {CREATE/ALTER/DROP} TABLE statements andALTER...COMPILE are allowed.Triggers: Usage Information 9-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!