Use of triggers in Oracle (based on system events and user events)

Source: Internet
Author: User

 
  1. ReateOr Replace TriggerTr_insert_emp
  2. BeforeInsert
  3. OnEmpForEach row
  4. Begin
  5. Insert IntoAValues(: New. empno,: new. ename,: new. job,: new. mgr,: new. hiredate,: new. sal,: new. comm,: new. deptno );
  6. End;
  7. Insert IntoEmpValues(1,'A','Soft', 4, to_date ('2017-09-12','Yyyy-MM-dd'), 1, 1, 20 );
  8. Select*FromA;

: New. data,: old. data

Triggers based on system events and user events,

For example, when the database is started

 
  1. Create Or Replace TriggerTr_db_log
  2. AfterStartup
  3. On Database
  4. Begin
  5. -- Do what you want to do!
  6. End;

And you can use before shutdown.

When the table is cleared, the trigger
Create or replace trigger tr_truncate_table
After truncate
Begin
Insert into A_table values (ora_dict_obj_name, user, sysdate );
-- Ora_dict_obj_name specifies the name of the object to be deleted.
End;

Disable a trigger
Alter tirgger tr_name disable;

Enable trigger
Alter trigger tr_name enable;

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.