How to treat the trigger below so that operations performed between 11/21/2016 and 12/20/2016 return date 01/20/2017 instead of 01/20/2016. p>
DECLARE
P_COUNT NUMBER(5);
DIA_VENDA VARCHAR(2);
MES_VENDA VARCHAR(2);
MES_VENDA2 VARCHAR(2);
MES_VENDA_DEPOIS VARCHAR(2);
ANO_VENDA VARCHAR(4);
P_DATA DATE;
P_DATA2 DATE;
BEGIN
IF :NEW.CODTIPVENDA=33 AND :NEW.TIPMOV IN('P') THEN
SELECT TO_CHAR(SYSDATE,'DD') INTO DIA_VENDA
FROM DUAL;
SELECT TO_CHAR(ADD_MONTHS(sysdate,1),'MM') INTO MES_VENDA
FROM DUAL;
SELECT TO_CHAR(ADD_MONTHS(sysdate,2),'MM') INTO MES_VENDA_DEPOIS
FROM DUAL;
SELECT TO_CHAR((sysdate),'MM') INTO MES_VENDA2
FROM DUAL;
SELECT TO_CHAR(sysdate,'YYYY') INTO ANO_VENDA
FROM DUAL;
P_DATA:= TO_DATE('20'|| MES_VENDA_DEPOIS || ANO_VENDA,'DD/MM/YYYY');
P_DATA2:= TO_DATE('20'|| MES_VENDA || ANO_VENDA,'DD/MM/YYYY');
IF DIA_VENDA >= '21' AND DIA_VENDA <='31' THEN
UPDATE TGFFIN
SET DTVENC = P_DATA
WHERE NUNOTA = :NEW.NUNOTA;
END IF;
IF DIA_VENDA >= '01' AND DIA_VENDA <='20' THEN
UPDATE TGFFIN
SET DTVENC = P_DATA2
WHERE NUNOTA = :NEW.NUNOTA;
END IF;
END IF;
END;
/