问题代码:
create or replace trigger securityemp
before insert
on emp
begin
if to_char(sysdate,\'day\') in (\'tuesday\') or
to_number(to_char(sysdate,\'hh24\')) not between 9 and 24 then
--禁止insert
raise_application_error(-20001,\'禁止星期二或者0~9间插入新员工\');
end if;
end securityemp;
问题:当在星期二时,仍可以进入插入数据操作
原因:他的返回值右面补了两个空格,也就是说他返回的不是“tuesday”,而是“tuesday ”
解决:加两个空格或加trim(..)
解决代码1:
create or replace trigger securityemp
before insert
on emp
begin
if to_char(sysdate,\'day\') in (\'tuesday \') or
to_number(to_char(sysdate,\'hh24\')) not between 9 and 24 then
--禁止insert
raise_application_error(-20001,\'禁止在非工作时间插入新员工\');
end if;
end securityemp;
解决代码2:
create or replace trigger securityemp
before insert
on emp
begin
if trim(to_char(sysdate,\'day\')) in (\'tuesday\') or
to_number(to_char(sysdate,\'hh24\')) not between 9 and 24 then
--禁止insert
raise_application_error(-20001,\'禁止在非工作时间插入新员工\');
end if;
end securityemp;
继续阅读与本文标签相同的文章
下一篇 :
5G商用重磅前夜,IPTV渗透率大曝光!
-
数十万共享雨伞不翼而飞,创始人却高兴的要命!网友:赚翻了
2026-05-18栏目: 教程
-
滴滴 这是一见钟情的感脚
2026-05-18栏目: 教程
-
以实践的方式讨论:N-Gram原理与其应用
2026-05-18栏目: 教程
-
Hi拼团,第六代云服务器拼团购买更便宜,低至148元/年
2026-05-18栏目: 教程
-
汇编(五)栈、CPU提供的栈机制、push、pop指令
2026-05-18栏目: 教程
