Link to home
Create AccountLog in
Avatar of amutallibkhan
amutallibkhanFlag for Saudi Arabia

asked on

Create Trigger, when new table is created in Oracle DB

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.

Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

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
-- if you want anything else to be done.. you can add here...
insert into xxpqr@dblink_db2 values(:new.col1, :new.col2,:new.col3 );

what are you trying to do ? can you explain in more details so there could be a better approach than this..
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 :
Avatar of amutallibkhan



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.

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.
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.
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 ?

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 ? specific time.(Night time preferable)
But the data should be pushed finally.
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.

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.

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,
Just give couple of mins.. i can give more details after discussing with USER.
Avatar of POracle
Flag of India image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account