Test dblink trigger transaction

Source: Internet
Author: User

Step 1: Create a table in database TW
Conn system/passwd @ TW;
Create user test identified by test;
Grant connect to test;
Grant create table to test;
Alter user test quota 1 m on users;
----------------------
Conn test/test @ TW;
Create Table Test (name varchar2 (20 ));
Insert into test values ('from _ TW ');

 

Step 2: Create a table in database tw1
Conn system/passwd @ tw1;
Create user test identified by test;
Grant connect to test;
Grant create table to test;
Alter user test quota 1 m on users;
Grant create trigger to test;
--------------------------
Conn test/test @ tw1;
Create Table Test (name varchar2 (20 ));
Insert into test values ('from _ tw1 ');

 

Step 3: Create a dblink and trigger in tw1
Create public database link totw connect to test identified by test using 'tw ';
---------------------
Create or replace trigger write_tw_test
After insert on Test
Referencing old as old New as new
For each row
Begin
Insert into Test. Test @ totw (name) values (: New. Name );
Dbms_output.put_line ('--- inserting ---');
End;
/

 

Step 4: Demo

 

Step 5: Conclusion
The trigger operation and trigger event belong to the same transaction. The trigger and trigger event are committed and rolled back together (same as dblink)
A row-Level Trigger is triggered when a row changes. Only after the trigger completes its operations will the subsequent events continue (waiting for the trigger to complete)

 

Step 6: test whether the trigger works in dblink (TW)
Create or replace trigger read_insert
After insert on Test
For each row
Begin
Insert into test1 values ('read _ from_tw1 ');
End;
/-- Work

-- It is easy to wait for the trigger to complete all operations, and wait for the lock

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.