Create a trigger for two tables

Scripts Diversos para o Oracle SQL*Plus. (Relacionado a ferramenta Oracle SQL*Plus, para questões de SQL, usar o forum SQL)
Post Reply
Dukiz
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 2
Joined: Tue, 31 Aug 2010 12:38 pm
Location: Maringá

Speaks galera ..

I'm starting in the Oracle world and my question I believe to be simple for those who understand how the people here ..

99] I would like to create a table with monthly expenses.

For this, I created a table that I will name 'movements' with:

Select all

DATA                                               DATE 
VALOR                                              NUMBER(10) 
TIPO                                               CHAR(1) 
HISTORICO                                          VARCHAR2(40)
is in this table where I go Do the inserts

on another table named 'NOOMEXER', I created the table that I will use in the trigger q will only be for viewing.

Select all

SALDO                                              NUMBER(10) 
CREDITO                                            NUMBER(10) 
DEBITO                                             NUMBER(10) 
SALDO_ATUAL                                        NUMBER(10)
Now I started using the triggers and that's where I hit

I'll insert values ??in the tables table and I need the value that I give insert and the type of the other table enter into the credit or debit depending on the number

hence I began:

Select all

create trigger teste 
after insert on tabel movimentações 
begin 
if tipo = '1' then valor = //do debito da segunda tabela// 
elsif tipo = '2' then valor = //do credito da segunda tabela//

How do I do this?
Did you understand or become confused?
Dukiz
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 2
Joined: Tue, 31 Aug 2010 12:38 pm
Location: Maringá

Sorry
I miss what I wrote on the trigger

would be like this:

Select all

create trigger teste  
after insert on tabel movimentações  
begin  
if tipo = '1' then DEBITO (2a tabela) = valor (1a tabela)  
elsif tipo = '2' then CREDITO (2a tabela) = valor (1a tabela) 
How to do this?
gfkauer
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 389
Joined: Tue, 27 Jul 2010 1:34 pm
Location: Sapiranga - RS
Contact:
Quem falou que programar era fácil??

Quanto mais dificil for a implementação mais valorizado seu trabalho será!

Acessem: www.gfkauer.com.br

From what I understand you need to use in the table movements table data nomexer correct?


maybe something so solve his nescessity ....

Select all

 
create or replace trigger teste 
  before  on movimentacoes   
  for each Row 
Declare 
  v_debito     naomexer.debito%Type; 
  v_credito    naomexer.credito%Type; 
  Cursor c_001 Is 
    Select debito, 
           credito 
      From naomexer; 
   -- onde esta o link entre a tabela "não mexer" e a "movimentacoes" 
begin 
  Open c_001; 
  Fetch c_001 Into v_debito, v_credito; 
  Close c_001; 
  If tipo = 1 Then 
    :New.valor := v_debito; 
  Elsif tipo = 2 Then 
    :New.valor := v_credito; 
  End If; 
end teste; 
 
 
Surgiu-me uma duvida, como a tabela não mexer se relaciona com a movimentação?
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests