Historical data of oracle statement-level triggers

Source: Internet
Author: User

Oracle statement-level triggers use historical data of operations in oracle. There are three types of triggers: Row-level triggers, statement triggers, and alternative triggers. Here we discuss statement triggers, because statement-level triggers do not have the new and OLd types to access historical data, but in many cases, you must use the newly updated or deleted data for other operations. The following provides a solution: first, define a table type structure, and then create a row-Level Trigger. This trigger only performs one operation, that is, record the data in the previous operation using old and new, and then create a statement-Level Trigger, execute corresponding business operations in this statement-Level Trigger. The specific implementation is as follows: (the two tables f are aaaa and aaaa_log respectively. The function is to delete aaaa data records to aaaa_log) -- create a package, create or replace package tri_pkg as type TempTable is table of aaaa % rowtype index by binary_integer; oldrows TempTable; oldemptyrows TempTable; end tri_pkg; -- clear the initialization data before deletion create or replace trigger into deleteon aaaa begintri_pkg.oldrows: = success; end; -- create or replace trigger aaaa_delete_rowAFTER deleteon aaaafor each rowdeclare num integer: = tri_pkg.oldrows.COUNT + 1; begin tri_pkg.oldrows (num ). name: =: old. name; tri_pkg.oldrows (num ). birthdate: =: old. birthdate; end; -- Statement trigger operation business create or replace trigger aaaa_deleteAFTER deleteon aaaa declare begin for I in 1 .. tri_pkg.oldrows.COUNT loop insert into aaaa_log (name, birthdate) select tri_pkg.oldrows (I ). name, tri_pkg.oldrows (I ). birthdatefrom dual; end loop; end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.