create or replace trigger actualizar_venta after insert or update or delete on ventas for each rowdeclare -- local variables here v_cantstock number(4); v_umbral number(4); v_provee varchar2(5); v_cant_actualizar number(4):=0;begin --inicializamos varibles select stock,umbral,cod_proveedor into v_cantstock,v_umbral,v_provee from productos where cod_producto = :new.cod_producto; --almacena la cantidad restante entre las unidades vendias y el stock v_cant_actualizar:= v_cantstock - :new.uni_vendidas; if inserting or updating then if v_cant_actualizar < 0 then raise_application_error (-20001,'Lo siento, pero no puedes vender tanto, ' ||'solo tenemos: '||v_cantstock||' unidades.'); end if; if v_cant_actualizar < v_umbral then dbms_output.put_line('Se realizara un pedido, ya que las existencias estan por debajo del umbral'); realizar_pedido(:new.cod_producto,((v_umbral*3)-v_cantstock),v_provee); end if; update productos set stock=v_cant_actualizar where cod_producto= :new.cod_producto; end if;/* if updating then end if;*/ if deleting then dbms_output.put_line('estas borrando un venta, se actualiza el stock'); update productos set stock=:old.uni_vendidas + v_cantstock where cod_producto=:old.cod_producto; end if; end actualizar_venta;