Oracle Database Table Data Synchronization-triggers

Source: Internet
Author: User

Create or replace
Trigger
"User_trigger"
After insert
Or delete
Or update
On users
-- Three trigger events
For each row -- Row-Level Trigger
Begin
If inserting
Then
Insert into users2
Values (: New
. Lid,: New. strname,: New. straddress );
Elsif deleting
Then
Delete from users2
Where users2.lid =: Old. lid;
Elsif updating
Then
Update users2
Set users2.strname =: New. strname, users2.straddress =: New. straddress where users2.lid =: Old
. Lid;
End if;
End;

 

1. Which of the insert/update/delete triggers the trigger, you can use the inserting/updating/deleting condition predicate in the trigger for judgment.

2. New and: Old: Must be for Row-level triggers. That is to say, the triggers using these two variables must have for each row.

These two variables are the array variables automatically provided by the system: New is used to record the newly inserted value, and old is used to record the deleted value;

When using insert, only values in new are available;

When using Delete, only values in old are available;

When update is used, values in new and old are available;

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.