例外
2015-07-21 08:01
417 查看
Oracle 例外学习练习
--no_data_found declare pename emp.ename%type; begin select ename into pename from emp where empno = 1234; exception when no_data_found then dbms_output.put_line('没有找到该员工'); when others then dbms_output.put_line('Other'); end; --too_many_rows declare pename emp.ename%type; begin select ename into pename from emp where deptno = 10; exception when too_many_rows then dbms_output.put_line('select into 匹配多行'); when others then dbms_output.put_line('Other'); end; --zero_divide declare pnum number; begin pnum := 1 / 0; exception when zero_divide then--then相当于一个大括号,可以有多条语句 dbms_output.put_line('1.0不能做被除数'); dbms_output.put_line('2.0不能做被除数'); when others then dbms_output.put_line('其他'); end; --value_error declare pnum number; begin pnum := 'abc'; exception when value_error then dbms_output.put_line('类型错误'); when others then dbms_output.put_line('其他'); end; --自定义例外:查询50号部门的员工姓名 declare cursor cemp is select ename from emp where deptno = 50; pename emp.ename%type; no_emp_found exception; --自定义例外 begin open cemp; fetch cemp into pename; if cemp%notfound then raise no_emp_found; end if; exception when no_emp_found then dbms_output.put_line('没有找到员工'); when others then dbms_output.put_line('Others'); close cemp; end;
相关文章推荐
- React Native开发的通讯录应用
- Windows App开发之集合控件与数据绑定
- 分享.NET系统开发过程中积累的扩展方法
- HTML学习笔记——锚链接、pre标签、实体
- 关于Win7 x64下过TP保护(内核层)(转)
- 交换机的工作原理
- MySQL(9):列的属性
- beaglebone black 解决盘符不显示的终极解决办法
- 前端页面——AJAX是个什么样的传输机
- 关于Win7 x64下过TP保护(应用层)(转)
- 4. JavaSE-数组 & 常用算法
- PYTHON单元测试
- listview添加行
- PHP_File文件操作简单常用函数
- 用指针引用数组元素并打印输出
- 小样本分析(二)
- 11g RAC to Single Dataguard 配置方式(RMAN)
- UVa12107 - Digit Puzzle
- 朴素贝叶斯算法(Naive Bayes)
- 内容运营的基本素养