oracle - Trigger not updating table -


i have function/trigger

create or replace function carrinho_saldo   (car in number default null)   return number     sald number;   begin    select saldo sald carrinho_compra   conta = car;    return sald;  end carrinho_saldo;  create or replace trigger efetuar_compra_trigger   after    insert or update     on efetuar_carrinho_compra    each row    declare    sald number;   begin    sald:=carrinho_saldo(:new.conta);    if :new.compra = 'c'    sald := sald - :new.valor;    else    sald := sald + :new.valor;   end if;    update carrinho_compra set saldo = sald     conta = :new.conta;   end; 

its supose work like;everytime add in "efetuar_carrinho_compra"table table carrinho_compra have update "saldo".i insert correctly

  insert efetuar_carrinho_compra(conta,id_compra,compra,valor,data) values(2,616,'c',1000,'30-06-2017'); 

the table "efetuar_carrinho_compra" updates ok.but table carrinho_compra dont values supose update insert.

if there isn't row in carrinho_compra conta = 2 first time trigger invoked, trigger fail because select saldo sald carrinho_compra in carrinho_saldo procedure throw no_data_found exception, isn't trapped anywhere. might try revising carrinho_saldo trap no_data_found exception , deal reasonably:

create or replace function carrinho_saldo     (car in number default null)   return number    sald number;  begin    begin     select saldo       sald carrinho_compra       conta = car;   exception     when no_data_found       sald := 0;   end;    return sald; end carrinho_saldo; 

best of luck.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -