oracle教程:异常处理

桃扇骨 2023-10-15 09:49 22阅读 0赞
  1. --异常处理1
  2. declare
  3. v_price number(10,2);--单价
  4. v_usenum2 number(10,2);--吨数
  5. v_money number(10,2);--金额
  6. v_account t_account%rowtype;--台帐行记录类型
  7. begin
  8. v_price:=2.45;--单价赋值
  9. -- v_usenum:=9999;--水费字数
  10. select into v_account from t_account
  11. where year='2012' and month='01' and ownerid=200;
  12. v_usenum2:=round(v_account.usenum/1000,2);--吨数
  13. v_money:=v_usenum2v_price;--金额
  14. dbms_output.put_line('水费字数:'||v_account.usenum||'金额:'||v_money);
  15. exception
  16. when no_data_found then
  17. DBMS_OUTPUT.put_line('没有数据');
  18. end;
  19. --异常处理2
  20. declare
  21. v_price number(10,2);--单价
  22. v_usenum2 number(10,2);--吨数
  23. v_money number(10,2);--金额
  24. v_account t_account%rowtype;--台帐行记录类型
  25. begin
  26. v_price:=2.45;--单价赋值
  27. select into v_account from t_account
  28. where year='2012' ;
  29. v_usenum2:=round(v_account.usenum/1000,2);--吨数
  30. v_money:=v_usenum2v_price;--金额
  31. dbms_output.put_line('水费字数:'||v_account.usenum||'金额:'||v_money);
  32. exception
  33. when no_data_found then
  34. DBMS_OUTPUT.put_line('没有数据');
  35. when too_many_rows then
  36. DBMS_OUTPUT.put_line('返回多行');
  37. end;

发表评论

表情:
评论列表 (有 0 条评论,22人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Oracle异常处理

    在编写PL/SQL程序时,避免不了会发生一些错误,可能是程序设计人员自己造成的,也可能是操作系统或硬件环境出错,比如出现除数为零、磁盘I/O错误等情况。对于出现的这些错误,Or