v-bind例外_例外-2

v-bind例外

Zero_divide的示例示例

===============================


Declare
I Int:=&i;
J Int:=&j;
K Int;
Begin
K:=i/j;
Dbms_output.put_line(k);
Exception
--if j=0 then (dividng the number by zero)
When Zero_divide Then
Raise_application_error(-20002,'cant Divide By Zero.....!');
When Others Then
Raise_application_error(-20003,'some Other Error........!');
End; 
Zero_divide ----在算术运算中将任何数字id除以零时会引发此异常。

No_data_found的示例示例

=============================


Declare
Name Varchar2(20);
No Int:=&no;
Begin
Select Ename Into Name From Emp Where Empno=no;
Dbms_output.put_line(name);
Exception
When No_data_found Then
Raise_application_error(-20002,'no Data Is Found For This Record.....!');
When Others Then
Raise_application_error(-20003,'some Other Error........!');
End; 
No_data_found ---如果对语句的任何选择均无法从数据库表中检索任何数据,则会引发此异常。 如果不加以处理,可能会在进一步的数据处理中产生错误。

invalid_cursor的样本示例

============================


DECLARE
CURSOR c1 IS SELECT ename FROM emp WHERE ROWNUM < 11;
name emp.ename%TYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO name;
EXIT WHEN c1%NOTFOUND;
dbms_output.put_line(c1%ROWCOUNT || '. ' || name);
END LOOP;
--cursor is closed
CLOSE c1;
--again trying to access the cursor variable after cursor is closed ,which raises an exception
dbms_output.put_line(c1%ROWCOUNT); 
exception
when invalid_cursor then
raise_application_error(-20001,'invalid operation in cursor');
END; 
invalid_cursor-此说明是不言自明的。 引发与游标有关的无效操作。

注意-在上面的示例中,它引发了异常,因为程序在关闭游标之后尝试访问游标变量%ROWCOUNT。

DUP_VAL_ON_INDEX的样本示例

=================================


create procedure insdept(num  number,name varchar2)
is
begin
insert into dept(deptno,dname) values (num,name);
commit;
dbms_output.put_line('One row inserted...!');
exception
when dup_val_on_index then
raise_application_error(-20001,'duplicate entry...!');
when others then
raise_application_error(-20002,'some other error occured...!');
end; 
DUP_VAL_ON_INDEX -----如果在主键/唯一字段上插入重复值,则会引发此异常。 用于维护数据完整性。

示例示例显示TOO_MANY_ROWS

=================================


declare
name varchar2(20);
begin
select ename into name from emp where deptno=&deptnumber;
dbms_output.put_line(name);
exception
when NO_DATA_FOUND then
raise_application_error(-20001,'no such data found...1');
when TOO_MANY_ROWS then
raise_application_error(-20002,'more than one matching record found...!');
when OTHERS then
raise_application_error(-20003,'some unexpected error occured...!');
end;  
TOO_MANY_ROWS ---如果选择的数据量超出了select语句中可存储在目标变量中的数据量,则会引发此异常。

还要检查

例外-3

翻译自: https://bytes.com/topic/oracle/insights/748330-exceptions-2-a

v-bind例外

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值