Trigger to enter data from two tables in just one.

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

I have two tables related by an FK.
I need that when entered data in these tables, a trigger is triggered that you take the data of these two tables and insert in only another third table.
Can anyone give help?
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Petter, some doubts Brother:

1) Will you do some logging scheme?
2) Simultaneously, or can they be two triggers, one on each table?

Whatever it sends there.
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

I will not require logging, the INSERT in the third table will have to be simultaneous.
User avatar
fabricio.silva
Rank: Programador Pleno
Rank: Programador Pleno
Posts: 34
Joined: Mon, 12 Mar 2007 7:07 am
Location: Catanduva/SP
Fabricio M. Silva
Oracle Certified Associate
------------------------------
Catanduva - SP

Hello colleague,

Is it possible to create a view of these two tables?

If yes, you could create a trigger instead of in the view and make the inserts you need.

ABS.
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

Guys vlw by force but I managed to do everything on top of a single trigger without having to create a view.
vlw.
Hahu
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 147
Joined: Thu, 16 Mar 2006 11:26 am
Location: São Paulo
O mundo gira muito!!

Speak Pyro,
Good morning,

Friend, it provides the solution to the glufke galera if possible, so the circular information ... Exchange the table name by tab_a and column, by col_a ... by the privacy issue of your company !!

Anything posts here in the forum!

abs hahu
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

Follow how the final trigger was:

Select all

 
create or replace trigger insert 
  after insert on tab_a  
  for each row 
declare 
  bb      number(6); 
  b       number(5); 
begin 
  select cod_b, cod_bb  
         into b,  
              bb 
  from tab_b 
  where bbb = :new.b1; 
 
  insert into tab_c(c1, c2, c3, c4, c5) 
         values(:new.b2, :new.b3, :new.b4, bb, b);      
end insert; 
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest