17,090
社区成员
发帖
与我相关
我的任务
分享
SQL> create or replace procedure proc_test_continue
2 as
3 v_num number(10);
4 begin
5 for i in 1..10 Loop
6 declare
7 v_c varchar2(10);
8 begin
9 v_c:='123';
10 select a into v_num from t_test where a=i; -- 查不到就抛no_data_found
11 dbms_output.put_line('we get it');
12 exception when no_data_found then -- 遇到异常做一些处理
13 dbms_output.put_line('something wrong');
14 exit;
15 end;
16 end Loop;
17 dbms_output.put_line('exit successful');
18 end;
19 /
Procedure created
SQL> exec proc_test_continue
we get it
something wrong
exit successful
PL/SQL procedure successfully completed
SQL>
SQL> set serveroutput on
SQL> create or replace procedure proc_test_continue
2 as
3 v_num number(10);
4 begin
5 for i in 1..10 Loop
6 begin
7 select a into v_num from t_test where a=i; -- 查不到就抛no_data_found
8 dbms_output.put_line('we get it');
9 exception when no_data_found then -- 遇到异常做一些处理
10 dbms_output.put_line('something wrong');
11 end;
12
13 end Loop;
14 end;
15 /
Procedure created
SQL> exec proc_test_continue
we get it
something wrong
something wrong
something wrong
something wrong
something wrong
something wrong
something wrong
something wrong
something wrong
PL/SQL procedure successfully completed
SQL>
declare
v_name varchar2(50);
begin
for i in 100..300 loop
begin
select first_name || '.' || last_name into v_name from employees where employee_id = i;
dbms_output.put_line('#' || i || ': ' || v_name);
exception
when no_data_found then
dbms_output.put_line('Not find #' || i);
when others then
exit;
end;
end loop;
end;