PL/SQL
declare
    v_empId emp.empno%type;
    
begin
    select empno into v_empId from emp where rownum = 999;     --异常,没有那么多行记录
    
    <<po1>>
    
    select empno into v_empId from emp where rownum = 1;
    
    dbms_output.put_line(' v_empId : ' ||  v_empId);
    
    exception
    when no_data_found then
         goto po1;
        
end;
1.上面select into v_empId 或用execute immediate SQLstr into v_empId 能不能不出异常 给个空值或''?2.出异常想继续执行,用goto报错 此处的goto无法转移至标记,怎么继续执行?

解决方案 »

  1.   

    select empno into v_empId from emp where rownum = 999;rownum=999? 有这么判的吗? 如果是处理异常可以使用begin
      select empno into v_empId from emp where rownum = 999;
    exception
    when others then 
       null;end;
      

  2.   

    select ... into...语句单独用一个begin ... exception ... end;段包含进去,就可以继续执行了。
    select into当没有记录时不能阻止发生异常,这是oracle规定的。