16.预定义例外2

3.dup_val_on_index
在唯一索引所对应的列上插入重复的值时,会隐含的触发例外dup_val_on_index

begin
insert into dept values(10,'公关部','北京');
exception
when dup_val_on_index then
dbms_output.put_line('在deptno列上不能出现重复值!');
end;


4.invalid_cursor
当试图在不合法的游标上执行操作时,会触发该例外
例如:试图从没有打开的游标提取数据,或是关闭没有打开的游标,则会触发该例外
SQL> declare
  2  cursor emp_cursor is select ename,sal from emp;
  3  emp_record emp_cursor%rowtype;
  4  begin
  5  --open emp_cursor;--打开游标
  6  fetch emp_cursor into emp_record;
  7  dbms_output.put_line(emp_record.ename);
  8  close emp_cursor;
  9  exception
 10  when invalid_cursor then
 11  dbms_output.put_line('请检查游标是否打开');
 12  end;
 13  /
请检查游标是否打开
PL/SQL procedure successfully completed


5.invalid_number
当输入的数据有误时,会触发该例外
比如:数字100写成了1oo就会触发该例外
begin
update emp set sal=sal+'1oo';
exception
when invalid_number then
dbms_output.put_line('输入的数字不正确');
end;


6.no_data_found
下面是一个pl/sql块,当执行select into 没有返回行,就会触发该例外
declare
v_sal emp.sal%type;
begin
select sal into v_sal from emp where ename='&name';
exception
when no_data_found then
dbms_output.put_line('不存在该员工');
end;






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值