一个简单触发器报错 --案例 : 星期一到星期五 早上8:00到晚上10:00期间不能对表dept进行相关dml操作
create or replace trigger tri_dept
before
insert or delete or update on dept
begin
if(to_char(sysdate,'day') in ('星期一','星期二','星期三','星期四','星期五'))
or (to_char(sysdate,'hh24:mi') between '08:00' and '22:00')
then
raise_application_error(-20001,'工作时间不允许对dept表进行相关操作');
end if;
end;
create or replace trigger tri_dept
before
insert or delete or update on dept
declare
v_flag number(1):=0;
begin
select count(*)
into v_flag
FROM DUAL
WHERE TO_NUMBER(TO_CHAR(SYSDATE, 'D')) BETWEEN 2 AND 5
AND TO_NUMBER(TO_CHAR(SYSDATE,'HH24')) BETWEEN 8 AND 22;
if v_flag>0 then
raise_application_error(-20001,'工作时间不允许对dept表进行相关操作');
end if;
end;
------解决方案--------------------
我按你这个把触发器创建了 创建成功 然后对表进行更新update dept set dname ='asking' where deptno=40; 照样更新成功了! ------解决方案-------------------- create or replace trigger tri_dept
before
insert or delete or update on dept
declare
v_flag number(1):=0;
begin
select count(*)
into v_flag
FROM DUAL
WHERE TO_NUMBER(TO_CHAR(SYSDATE, 'D')) BETWEEN 2 AND 5
AND TO_NUMBER(TO_CHAR(SYSDATE,'HH24')) BETWEEN 8 AND 22;if v_flag>0 then
raise_application_error(-20001,'工作时间不允许对dept表进行相关操作');
end if;
end;