Oracle triggers when updating

26-Feb-2018 10:52 by 3 Comments

Oracle triggers when updating

And that's the aspect of this feature that makes things so much easier when it comes to mutable table errors.Using this feature, I can combine all the different trigger events and code, plus they share scope like the subprograms of a package body.

This was all previously done using pencil, paper, and a calculator.

The common state is established when the triggering statement starts and is destroyed when the triggering statement completes, even when the triggering statement causes an error.

ne variables which persist through the execution of the steps defined in the compound trigger.

This blog articles offers a few examples of what can be done and needs to be done.

This article is based on the problem outlined in this Oracle Spatial forum thread to which I responded.

More reliable - you don't have to worry about managing the session-persistent collection.

Less code - always a nice thing, as long as the "less code" is also understandable and easy to maintain.Easy enough in PL/SQL, right in a database trigger (see links at bottom of post for discussions on whether or not you should put logic like this in your database triggers): CREATE OR REPLACE TRIGGER equitable_salary_trg AFTER INSERT OR UPDATE ON employees FOR EACH ROW DECLARE l_max_allowed employees.salary%TYPE; BEGIN SELECT MIN (salary) * 25 INTO l_max_allowed FROM employees; IF l_max_allowed The solution, conceptually, is simple enough.If I can do task X in the row level trigger, save whatever information I need to perform X on that row in a to-do list (a collection, perhaps? Then define an AFTER STATEMENT trigger that goes through the to-do list, and executes the desired logic for each row. If you put the collection in the specification, it can be modified by any schema with EXECUTE authority on the package, in whatever way anyone wants to mess with that collection. So I "hide" the list in the body and "expose" it through the procedures in the spec.The traditional (now, out-of-date) solution is to define a package that contains a collection defined at the package level. So I can add information to the collection within the row-level trigger, and it will still be there when I bubble up to the statement-level trigger. CREATE OR REPLACE PACKAGE BODY equitable_salaries_pkg IS TYPE id_salary_rt IS RECORD ( employee_id employees.employee_id%TYPE , salary employees.salary%TYPE ); TYPE g_emp_info_t IS TABLE OF id_salary_rt INDEX BY PLS_INTEGER; g_emp_info g_emp_info_t; g_corrections_in_process BOOLEAN := FALSE; PROCEDURE initialize IS BEGIN g_emp_info.Here's my package specification: CREATE OR REPLACE PACKAGE equitable_salaries_pkg IS PROCEDURE initialize; PROCEDURE add_employee_info ( employee_id_in IN employees.employee_id%TYPE , salary_in IN employees.salary%TYPE ); PROCEDURE make_equitable; END equitable_salaries_pkg; Huh. DELETE; END initialize; PROCEDURE finished_corrections IS BEGIN g_corrections_in_process := FALSE; END finished_corrections; PROCEDURE starting_corrections IS BEGIN g_corrections_in_process := TRUE; END starting_corrections; FUNCTION corrections_in_process RETURN BOOLEAN IS BEGIN RETURN g_corrections_in_process; END corrections_in_process; PROCEDURE add_employee_info ( employee_id_in IN employees.employee_id%TYPE , salary_in IN employees.salary%TYPE ) IS l_index PLS_INTEGER := g_emp_info.You might also find these resources helpful: ORACLE-BASE: Trigger Enhancements in Oracle Database 11g Release 1 ORACLE-BASE: Should you use triggers at all?

  1. dating latin women tips 27-Jan-2018 14:00

    Auch Normaler Sex mit reifen Frauen die auf privaten Telefonsex in allen Lebenslagen. Ich eine geile Hausfrau möchte mit mit per Telefonsex Hausfraunensex machen.