--系统异常 declare rowD user_tbl%rowtype; begin select * into rowD from user_tbl; dbms_output.put_line(rowD.id||‘‘||rowD.user_name||‘ ‘||rowD.password); exception when too_many_rows then dbms_output.put_line(‘不能将多行赋予一个属性!‘); end; or declare rowD user_tbl%rowtype; begin select * into rowD from user_tbl where id=5; dbms_output.put_line(rowD.id||‘ ‘||rowD.user_name||‘ ‘||rowD.password); exception when too_many_rows then dbms_output.put_line(‘不能将多行赋予一个属性!‘); when no_data_found then dbms_output.put_line(‘没有您要查找的数据!‘); end;
--自定义错误 declare invalidError exception; category varchar2(20); begin category:=‘&category‘; if category not in(‘附件‘,‘顶盘‘,‘备件‘) then raise invalidError; else dbms_output.put_line(‘您输入的类别是:‘||category); end if; exception when invalidError then dbms_output.put_line(‘无法识别的类别!‘); end;
--引发应用程序异常 declare app_exception exception; grade user_tbl.grade%type; begin select grade into grade from user_tbl where id=&id; if grade=‘A‘ then raise app_exception; else dbms_output.put_line(‘查询的等级为:‘||grade); end if; exception when app_exception then raise_application_error(-20001,‘未知的等级!‘); end; (编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|