sql - Update trigger when row doesn't exist -
i have 2 tables orderitems:
"order_items_code" varchar2(20) not null enable, "order_code" varchar2(20) not null enable, "item_code_orders" varchar2(20) not null enable, "order_quantity" number(4,0) not null enable, "order_unit" varchar2(5) not null enable, "unit_price" number(38,5), "ordered_in" varchar2(6), "or_quantity_ton" number(38,5), "warehouse_code" varchar2(20) not null enable
the other table inventory:
"inventory_code" varchar2(20) not null enable, "item_code" varchar2(20) not null enable, "warehouse_code" varchar2(20), "in_q_ton" number(38,5), "or_q_ton" number(38,5)
i created trigger calculate "or_quantity_ton" = sum ("or_qn_ton")
create or replace trigger sum_or_it after insert or update or delete on orderitems begin update inventory set or_q_ton = ( select sum(or_quantity_ton) orderitems orderitems.item_code_orders = inventory.item_code , warehouse_code = '1'); end;
this inventory table , column or_q_ton sum of ordered quantity every item,, if item doesn't exist in orders ,, want order quantity zero. want make exception if "item_code_orders" doesn't exist in table "orderitems" or_q_ton = 0
i tried didn't work got (-) not (0)
exception when no_data_found update inventory set or_q_ton = 0 ;
its not exception , , oracle not raise excpetion in case of update above need use sql%rowcount
,
try:
if sql%rowcount = 0 update inventory set or_q_ton = 0 ; end if;
Comments
Post a Comment