2014-09-04 44 views
0
create or replace trigger tri_hours 
before insert 
on dept 
begin 

    if (to_char(sysdate,'day')='sunday') then 
    raise_application_error(-20001,' Insert Opeartion not allow because today is sunday '); 
    else 
     if inserting then 
       --insert query on table dept 
     end if;  
    end if; 
end; 
/

当我尝试在星期日插入新记录时,触发器不起作用。火触发器只允许在星期一到星期六在PLSQL中完成交易Oracle

+2

问题是什么? – 2014-09-04 18:54:41

+0

在上面的代码中,请忽略raise_application_error(-20001,'INSERT DURING 09 to 18');然后考虑raise_application_error(-20001,'插入操作只允许在周一到周六之间'); – 2014-09-04 18:59:44

+0

我的问题是我在用户在周日插入新记录时触发了一个触发器。 – 2014-09-04 19:00:31

回答

3

使用带有to_char的日期格式掩码day会生成一个填充为9个带空格的字符的字符串。您需要使用fm格式掩码去除空格,即

if (to_char(sysdate,'fmday') = 'sunday') then 
相关问题