oracle10g- oracle关于数据操作时异常的处理 编写自定义的异常
异常处理
在plsql中的一个警告或错误的情形都被称为异常包括编译时和运行时的错误
异常分类
系统异常
自定义异常
异常结构
exception
when ... then
...
系统异常
dup_val_on_index 向有唯一约束的表中插入了重复行
no_data_found 在一个select into 语句中没有返回值
too_many_rows select into语句返回了多行
value_error 一个算法 转换 截断 或大小约束发生错误
zero_divide 发生被零除
--*****************************************
declare
test varchar2(10);
begin
select name into test from t1 where id=3333;
dbms_output.put_line(test);
end;
/
--***
declare
test varchar2(10);
begin
select name into test from t1 where id=3333;
dbms_output.put_line(test);
exception
when no_data_found then
dbms_output.put_line("没有找到数据!");
end;
/
--**********
declare
tname varchar2(10);
e exception;
begin
select name into tname from dept where id='30';
if tname<>'b部门' then
raise e;
end if;
dbms_output.put_line(tname);
exception
when e then
dbms_output.put_line('不是想要的部门');
end;
/

浙公网安备 33010602011771号