--首先创建一张空表
SQL> create table t as select * from emp where 1=2;
Table created
--创建一个存储过程,使用异常,打印错误信息
declare
v_ename varchar2(30);
begin
select ename into v_ename from t;
exception
when others
--no data found
then
dbms_output.put_line(sqlerrm);
end;
-----测试结果1:
SQL> declare
2 v_ename varchar2(30);
3 begin
4 select ename into v_ename from t;
5 exception
6 when others--no data found
7 then
8 dbms_output.put_line(sqlerrm);
9 end;
10 /
ORA-01403: 未找到任何数据
PL/SQL procedure successfully completed
-----测试结果2
SQL> declare
2 v_ename varchar2(30);
3 begin
4 select ename into v_ename from t;
5 /*
6 exception
7 when others--no data found
8 then
9 dbms_output.put_line(sqlerrm);*/
10 end;
11 /
declare
v_ename varchar2(30);
begin
select ename into v_ename from t;
/*
exception
when others--no data found
then
dbms_output.put_line(sqlerrm);*/
end;
ORA-01403: 未找到任何数据
ORA-06512: 在 line 4