----------- trigger ------------------ create or replace trigger actualizar_venta after insert or delete on ventas for each row declare -- local variables here v_cantstock number(4); v_umbral number(4); v_provee varchar2(5); v_cant_actualizar number(4); 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 if inserting then v_cant_actualizar:= v_cantstock - :new.uni_vendidas; if v_cant_actualizar < 0 then raise_application_error (-20001,'Lo siento, pero no puedes vender tanto, '|| 'solo hay :'||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_cant_actualizar),v_provee); end if; dbms_output.put_line('--- Se ha actualizado el stock --'); update productos set stock=v_cant_actualizar where cod_producto= :new.cod_producto; end if; if deleting then dbms_output.put_line('--- Se esta borrando un registro, se hara la correspondiente actualizacion. --'); update productos set stock= :old.uni_vendidas+v_cantstock where cod_producto= :old.cod_producto; end if; end actualizar_venta; -------------error------------------- delete from ventas * ERROR en línea 1: ORA-01403: no se han encontrado datos ORA-06512: en "SCOTT.ACTUALIZAR_VENTA", línea 10 ORA-04088: error durante la ejecución del disparador 'SCOTT.ACTUALIZAR_VENTA'