日期:2014-05-17  浏览次数:20987 次

用自定义异常没错,而非自定义异常却不行
create table cardInfo
 (cardId int primary key,
 password char(6) not null,
 money number);

 create table transInfo
 (cardId int references cardInfo(cardId),
 transtype char(4) check(transtype='支取' or transtype='存入'),
 transMoney number,
 transDate date);
---触发器
 create or replace trigger delTrans
 before
 delete
 on transInfo
 for each row
 begin
  if floor(months_between(sysdate,:old.transDate)) < 1 then
  raise_application_error(-20001,'dsa');
  end if;
 end;

 insert into cardInfo values(1,'dsad',23);
 insert into transInfo values(1,'支取',34,sysdate);


 --执行这句话时报错
 delete from transInfo where cardid=1;

ORA-20001: dsa
ORA-06512: 在 "ADMIN.DELTRANS", line 3
ORA-04088: 触发器 'ADMIN.DELTRANS' 执行过程中出错

查看错误堆栈的程序源?
 

------解决方案--------------------
报错,不就对了吗,错误码ORA-20001: dsa
说明floor(months_between(sysdate,:old.transDate)) < 1符合条件
如果把1改为0,可能就不报错了
------解决方案--------------------
这个报错不就是你自定义异常的目的吗?

你有没有用plsql块去做异常处理起来,当然应该就是直接提示错误吧。