сделал пока что так, потом буду пробовать
Код:
CREATE OR REPLACE TRIGGER SUPERMAG.LMMATRIXCHANGE
BEFORE DELETE OR INSERT
ON SUPERMAG.SMASSORTMATRIX
FOR EACH ROW
DECLARE
dayForZak int;
i int;
DDATE date;
DTEMP date;
IVT int;
f boolean;
BEGIN
SELECT TO_NUMBER(VALUE) into dayForZak FROM SUPERMAG.LMCONFIG WHERE PARM='day_for_vvod';
DTEMP := TO_DATE('01.01.2010','DD.MM.YYYY');
IVT := 0;
f := false;
FOR i in 1..366 loop
if (weekd(DTEMP) = dayForZak) then
IVT := IVT + 1;
end if;
if TO_CHAR(DTEMP,'DD.MM.YYYY') = TO_CHAR(sysdate,'DD.MM.YYYY') then
f := true;
end if;
if (weekd(DTEMP) = dayForZak) AND (IVT / 2 <> TRUNC (IVT / 2)) then
if f = true then
exit;
end if;
end if;
DTEMP := DTEMP + 1;
end loop;
if inserting or updating then
INSERT INTO LMMATRIXACTIONS(ARTICLE,ACTIONDATE,OWNER,ACTION,MATRIXID,LOCATION,ZAKDATE)
VALUES (:New.ARTICLE,SYSDATE,USER,'insert',:New.IDMATRIX,(SELECT STORELOC FROM SMASSORTMATRIXLOC WHERE IDMATRIX=:New.IDMATRIX),DTEMP);
else
INSERT INTO LMMATRIXACTIONS(ARTICLE,ACTIONDATE,OWNER,ACTION,MATRIXID,LOCATION) VALUES
(:Old.ARTICLE,SYSDATE,USER,'delete',:Old.IDMATRIX,(SELECT STORELOC FROM SMASSORTMATRIXLOC WHERE IDMATRIX=:Old.IDMATRIX));
end if;
END LMMATRIXCHANGE;
/