为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的触发器不能创建成功?

create or replace trigger securitytest

before insert

on test

begin

   if to_char(sysdate,'day') in ('saturday','sunday') or

      to_number(to_char(sysdate,'hh24')) not between 9 and 18 then

      raise_application_error(-200001,'cannot insert in woking time');

   end if

end;


正在回答

8 回答

test是你自己创建的表吗??oracle提示的错误信息是什么?

2 回复 有任何疑惑可以回复我~
#1

慕粉3344523 提问者

非常感谢!
2016-07-10 回复 有任何疑惑可以回复我~

百度一下

1 回复 有任何疑惑可以回复我~

1,首先你先用这个查一下:select  to_char(sysdate,'day') from dual;,看看结果是英文还是汉字,如果是汉字,就把: ('saturday','sunday') 改为: ('星期六','星期日')  

2,raise_application_error(-200001,'cannot insert in woking time');  这里的错误号参数的范围是-20000 到 -20999  你这里的-200001不在这个范围内

3 回复 有任何疑惑可以回复我~

还有一个:是-20001,不是-200001

1 回复 有任何疑惑可以回复我~

create or replace trigger securitytest

before insert

on test

begin

   if to_char(sysdate,'day') in ('saturday','sunday') or

      to_number(to_char(sysdate,'hh24')) not between 9 and 18 then

      raise_application_error(-200001,'cannot insert in woking time');

   end if

end;

 我改成上面的方式也不行呀

0 回复 有任何疑惑可以回复我~
#1

qq_骑着蜗牛去旅行_03471935

菇凉,你的错误号错了,范围是-20000(负两万)到-20999(负两万九百九十九),你写的是-200001(负二十万零一),多了个零
2016-07-08 回复 有任何疑惑可以回复我~

你的不是汉语星期六和星期日所以没有进if判断

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我的触发器不能创建成功?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信