How to ban a DDL action on oracle

Asked

Viewed 31 times

0

I want to do a Rigger that prohibits any DML operation on a given table. In case these are the parameters: between 20:00 to 06:00, and Sunday all day.

CREATE OR REPLACE TRIGGER TG_HORARIO
BEFORE UPDATE OR DELETE OR INSERT
ON XNOTA
FOR EACH ROW
DECLARE
    D_SEMANA INT;
    HORA INT;
BEGIN
    SELECT TO_CHAR(SYSDATE, 'd') INTO D_SEMANA FROM DUAL;
    SELECT TO_CHAR(SYSDATE, 'HH24') INTO HORA FROM DUAL;
    IF D_SEMANA <> 7 THEN
        IF HORA < 6 AND HORA > 20 THEN
            RETURN FALSE;
        END IF;
    END IF;
END;

NOTE: How should I proceed from the second if?

1 answer

1


CREATE OR REPLACE TRIGGER TG_HORARIO
BEFORE UPDATE OR DELETE OR INSERT
ON XNOTA
FOR EACH ROW
DECLARE
    D_SEMANA CHAR(1);
    HORA     CHAR(4);
BEGIN
    D_SEMANA := TO_CHAR(SYSDATE, 'd');--SELECT NAO NECESSARIO
    HORA     := TO_CHAR(SYSDATE, 'HH24');
    IF ((D_SEMANA = '1' OR (HORA < '0600' AND HORA > '2000')) THEN--TESTE DO HORARIO domingo e 1
            RAISE_APPLICATION_ERROR(-20001,'OPERACAO INVALIDA !!');
    END IF;
END;

Follows an example , I believe it is academic your problem , in a real case holidays may need to be treated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.