--例子:
declare
e_integerity exception;
e_no_employee exception;
pragma exception_init(e_integerity,-2291);
begin
update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
end if;
exception
when e_integerity then
dbms_output.put_line('该部门不存在');
when e_no_employee then
dbms_output.put_line('该员工不存在');
end;
刚学这个,感觉有些代码没有完全懂,希望得到解释,谢谢
declare
e_integerity exception;
e_no_employee exception;
pragma exception_init(e_integerity,-2291);
begin
update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
end if;
exception
when e_integerity then
dbms_output.put_line('该部门不存在');
when e_no_employee then
dbms_output.put_line('该员工不存在');
end;
刚学这个,感觉有些代码没有完全懂,希望得到解释,谢谢
解决方案 »
- oracle数据库?
- 救我。怎么在两条记录中取一条最新的?
- 在PLSQL里写存储过程中怎么传参数
- 求写复杂sql语句,有测试数据
- 聚集函数不能在WHERE中,可以用在 HAVING 子句中
- job 任务 重新启动服务器后 next date 变成4000-1-1,怎么调成正常?
- 怎样知道pl/sql developer用的是哪个TNSNAMES.ORA 文件中的配置。
- varchar & varchar2有什么区别?
- 我是菜鸟,如何进入Enterprise Manager啊?救命啊!
- SQLPlus中编辑的问题(菜鸟头都大)
- 很着急Oracle 语句错误 ORA-00933: SQL 命令未正确结束
- oracle 怎么修改主键类型
给oracle系统错误-2291指定一个异常名字e_integerity;这样就可以在exception子块中用这个名字来捕获异常。update scott.emp set deptno=40 where empno=-1;
if sql%notfound then
raise e_no_employee;
这里是说如果前面的update语句没有更新任何记录,就抛出异常e_no_employee