I have to create trigger that raises an error if I try to delete from table and the date on the table is equal with sysdate
.
This is my code:
create or replace trigger nonViolation
before insert or delete on reservation
for each row
declare
error exception;
error2 exception;
dateres date:=sysdate;
begin
if inserting then
if :new.dateDep<dateres then
raise error;
end if;
end if;
if deleting then
if (:OLD.datedep=dateres)
then
raise error2;
end if;
end if;
exception
when error2 then
raise_application_error(-20003,'supression impossible');
when error then
raise_application_error(-20001,'reservation impossible');
end;
I tried to delete a row that contain today'sdate 25-nov-18
and the trigger doesn't work. I tried to print the values of :old.datedep
and dateres
and they are the same:
25-nov-2018
25-nov-2018
Can someone help me? thank you
I suspect you're not allowing for the fact that SYSDATE contains the current time as well as the current date. Perhaps your trigger will produce the desired outcome if you remove the time element like this:
As @bobjarvis suggests you may need to strip the time element from
datedep
(depending on how you populate it):Try using a complete date format mask such as
'yyyy-mm-dd hh24:mi:ss'
and see what you actually have.