+ -
当前位置:首页 → 问答吧 → 一个简单的触发器问题

一个简单的触发器问题

时间:2011-11-09

来源:互联网

我要用触发器实现每天下班时间不能访问表:
create or replace trigger hospital14_dui
before insert or update or delete on hospital14
declare 
v_time varchar2(20);
begin
v_time:=to_char(sysdate,'hh24:mi:ss');
 if (v_time>17:00:00 or v_time<8:00:00)
 then
 raise_application_error(-2000,'a table can not be modified');
 end if;
end;

结果编译出错,是不是 if (v_time>17:00:00 or v_time<8:00:00)
这句写错了?该怎么改呢?

作者: zhoulirong14   发布时间: 2011-11-09

if (v_time>'17:00:00' or v_time<'8:00:00')

作者: yixilan   发布时间: 2011-11-09

就是这句写错了if (v_time>17:00:00 or v_time<8:00:00)
还有一个地方,错误号码范围不对,自定义错误只能用-20001~-20999之间的数字
create or replace trigger hospital14_dui
before insert or update or delete on hospital14
declare  
v_time varchar2(20);
begin
 v_time:=to_char(sysdate,'hh24:mi:ss');
 if (v_time>'17:00:00' or v_time<'8:00:00')
 then
 raise_application_error(-20001,'a table can not be modified');
 end if;
end;

作者: tx2730   发布时间: 2011-11-09

[code=SQL][/code]create or replace trigger hospital14_dui
before insert or update or delete on hospital14
declare
v_time varchar2(20);
begin
v_time:=to_char(sysdate,'hh24:mi:ss');
 if (v_time>'17:00:00' or v_time<'8:00:00')
 then
 raise_application_error(-2000,'a table can not be modified');
 end if;
end
少了引号。

作者: jg_huang   发布时间: 2011-11-09

引用 1 楼 yixilan 的回复:
if (v_time>'17:00:00' or v_time<'8:00:00')


谢谢,晕啊!好糊涂的我

作者: zhoulirong14   发布时间: 2011-11-09