create or replace trigger securityemp
before insert
on cc
for each row begin
  if to_char(sysdate,'day') in ('星期六','星期日','星期五') or
  to_number(to_char(sysdate,'hh24')) not between 9 and 18 then
  raise_application_error(-20202,'规定时间不允许插入');
  end if;
end;这样就ok了

解决方案 »

  1.   

    create or replace trigger securityemp
    before insert
    on emps
    declare
      out_worktime exception;
    begin
      if to_char(sysdate,'day') in ('星期六','星期日','星期五') or
      to_number(to_char(sysdate,'hh24')) not between 9 and 18 then
      raise out_worktime;
      end if;
      exception
      when out_worktime then 
         dbms_output.put_line('do not insert data during non-work time');
         raise_application_error(-20202,'规定时间不允许插入'); 
    end;
    /
    异常不能在触发器里处理掉,需要向外抛才能终端插入操作
      

  2.   

    为什么只能抛这种异常呢?这种异常是系统的吧?自定义异常为什么达不到目的呢,难道只有_application_error这种异常才行吗?
      

  3.   

    为什么只能抛这种异常呢?这种异常是系统的吧?自定义异常为什么达不到目的呢,难道只有_application_error这种异常才行吗?RAISE_APPLICATION_ERROR这个函数是将应用程序专有的错误从服务器端转达到客户端应用程序(plsql/sqlplus等)-20000到-30000是可以的自定义代码,否则会与oracle自带的冲突
      

  4.   

    为什么只能抛这种异常呢?这种异常是系统的吧?自定义异常为什么达不到目的呢,难道只有_application_error这种异常才行吗?RAISE_APPLICATION_ERROR这个函数是将应用程序专有的错误从服务器端转达到客户端应用程序(plsql/sqlplus等)-20000到-30000是可以的自定义代码,否则会与oracle自带的冲突
    学习啦