Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Create Trigger, when new table is created in Oracle DB

Posted on 2010-09-08
14
Medium Priority
?
821 Views
Last Modified: 2013-12-19
Hi Experts,

Want to create a trigger, when a new table (here the table is created dynamically,assume it is XXABC1)created in Oracle DB1. And need to insert the records from this table XXABC1 into another DB2 table (say XXPQR@DB2).
Something like INSERT INTO XXPQR@DB2 (select * from XXABC1)

Please do the needful.

Thanks.
0
Comment
Question by:amutallibkhan
14 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624690
setup an AFTER INSERT TRIGGER for the table XXABC1 in database DB1 to insert into XXPQR table in DB2 database.

Have a database link created with sample name as "dblink_db2"

create or replace trigger after_ins_xxabc1 after insert on xxabc1
for each row
begin
-- if you want anything else to be done.. you can add here...
insert into xxpqr@dblink_db2 values(:new.col1, :new.col2,:new.col3 );
commit;
end;
/

Thanks
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624694
what are you trying to do ? can you explain in more details so there could be a better approach than this..
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33624706
I understand you want a DDL trigger (AFTER CREATE) to check if a table was created, and run a CREATE TRIGGER with that table name :http://psoug.org/reference/ddl_trigger.html
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:amutallibkhan
ID: 33624847
Scenario:

I have a DB1, where the new tables created on daily basis.
I have another DB2, where I have a fixed table XXABC.

Need to do is, whenever the new table gets created in DB1, then the new table data should be pushed into DB2 fixed table XXABC.

Hope you got it clear.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624862
understood.

does your new table everyday gets created with data ? or data gets inserted into it after it gets created ? can you please be more precise so that we can clearly understand.
0
 

Author Comment

by:amutallibkhan
ID: 33624905
I'm sorry, missed one point.

Actually the new Table is created monthly once, not daily wise, to capture the monthly transactions. Like SEP10ABC. Later the data is inserted.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624914
so this is the information which is required for us to understand. Do you want your fixed table to be populated in the DB2 immediately after each row gets inserted into this monthly table or during the night time or at a fixed time ?

Thanks
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624921
i mean can we populate the data into DB2 immediately or should we do it every day night or every 1 hour or at the month end ?
0
 

Author Comment

by:amutallibkhan
ID: 33624944
Anytime..no specific time.(Night time preferable)
But the data should be pushed finally.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624969
then trigger is not the right stuff here.. just have a sql script scheduled which can insert the data into that fixed table in DB2 everytime ( some time say 10:30 PM everyday ) from the new table.

note:
1) the sql script should identify what data it need to insert. it should not duplicate.
2) use dbms_job/dbms_scheduler or unix script to automate the job.

Thanks
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 33624978
if you use a trigger to populate the fixed table, that would degrade the performance of the transactions related to the new table if that is going to be used by  other processes/users/transactions. Thanks,
0
 

Author Comment

by:amutallibkhan
ID: 33625043
Just give couple of mins.. i can give more details after discussing with USER.
0
 
LVL 8

Accepted Solution

by:
POracle earned 1500 total points
ID: 33634708
You can go with DDL trigger.
Benefit :
->Trigger will take care about consistency between two table reside in different database. means Trigger will ensure that when record insert in one table it will propagate to another table. if it fail to insert into DB2 then whole transaction will be rollback.
->Require less intervention from your side.

Drawbacks:
->May slow down your insert, but this is depend on your environment.

Another way:-

Create partition table on DB2.
insert data in table@db1
move data from db1 to db2 using exchange partition.

0
 

Author Closing Comment

by:amutallibkhan
ID: 33747340
Thanks.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question