本帖最后由 keanu196492 于 2010-09-27 16:37:28 编辑

解决方案 »

  1.   


    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;
      

  2.   

    SQL> set serveroutput onSQL> 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> 
      

  3.   

    块的基本形式
    declare
    begin
    exception
    enddeclare里面的变量仅在本块及其子块有意义.类似c里面函数的局部变量.
      

  4.   

    10g不支持continue,但是有exit11g才支持continue
      

  5.   

    多谢LS的2位,我去试试,OK的话,分都给你们
      

  6.   

    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>