Oracle triggers. When a table is updated or inserted, data is synchronized to a table in another database. oracle Data is synchronized.

Source: Internet
Author: User

Oracle triggers. When a table is updated or inserted, data is synchronized to a table in another database. oracle Data is synchronized.

Two tables are the T_SRC_WEATHER_TSPG fields under User,

User B's t_src_weather table,

It is required that when the T_SRC_WEATHER_TSPG table under user A is inserted or updated, the data is synchronized to the t_src_weather table under user B,

Create a trigger. The SQL statement is as follows:

Create or replace trigger weather_history_update -- weather_history_update indicates the TRIGGER name.
AFTER update or insert on Yjzhaccess. T_SRC_WEATHER_TSPG -- AFTER specifies the trigger time. on is followed by the table name, that is, the trigger time when the table Yjzhaccess. T_SRC_WEATHER_TSPG is updated or inserted.
For each row -- each row
Begin
Insert into yjzhhistory. t_src_weather (ID, SSXQMC, SSXQDM, HISTIME, WEATHER) -- specify the inserted Table and fields
VALUES (: new. ID,: new. MC,: new. ID,: new. gxsj,: new. type); -- Introduce the newly inserted data to this table.
End;

After execution, execute insert into Yjzhaccess. t_SRC_WEATHER_TSPG values (23, 'twenty-three brigade ', 66.66, 16.66, 'snow', 66, sysdate) exception, reported ora-04098: the trigger is invalid and has not been re-verified. Enter the trigger through plsql developer to find the compilation error:

If the error is found to be unauthorized, log on to the dba and grant the insert permission to the table under user B to user A: grant insert on yjzhhistory. t_src_weather to yjzhaccess

After the permission is granted, run the test update statement again. The update statement is successful. At this time, the trigger executes the trigger event, and the corresponding data exists in both tables.

 

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.