Cita:
Iniciado por huesos52
Código SQL:
Ver originalCREATE OR REPLACE TRIGGER TR_CALCULARMORA
BEFORE UPDATE
ON Prestamo
Por que BEFORE UPDATE?
Yo creo que:
Utilizar
Código SQL:
Ver originalCREATE OR REPLACE package test_Package AS
TYPE TTmpRec IS record (id_lib INTEGER, Mora INTEGER);
TYPE TTmpTabla IS TABLE OF TTmpRec INDEX BY binary_integer;
TempTabla TTmpTabla;
Latch BOOLEAN:=FALSE;
PROCEDURE Update_Data;
END;
/
CREATE OR REPLACE TRIGGER TR_CALCULARMORA_TMP
AFTER UPDATE
ON Prestamo
FOR EACH ROW
DECLARE
dias INTEGER;
fechaDevOriginal DATE;
BEGIN
SELECT fechaDev INTO fechaDevOriginal FROM Prestamo WHERE idLector=:OLD.idLector AND idLibro=:OLD.idLibro;
SELECT trunc(sysdate) - to_date(fechaDevOriginal, 'dd-mm-yyyy') INTO dias FROM dual;
IF dias > 3 THEN
Test_Package.TempTabla(:OLD.idLector).id_lib:=:OLD.idLibro;
Test_Package.TempTabla(:OLD.idLector).Mora:=(dias-3)*5;
END IF;
END;
/
CREATE OR REPLACE TRIGGER TR_CALCULARMORA
After INSERT OR UPDATE OR DELETE ON Prestamo
BEGIN IF test_Package.Latch THEN
Test_Package.Update_Data;
END IF;
END;
/
Yo escribo procedure Update_Data mas tarde (pordegracias, no tengo tiempo ahora)