if then 
else 
endif

解决方案 »

  1.   

    declare
      cursor c_id is select id from test;
      name t1.name%type;
    begin
      for i in c_id
      loop
        select name into name from t1 where id = i.id and rownum <= 1;
        if SQL%NotFound then
          null;
        else
          dbms_output.put_line('取到数据');
        end if;
      end loop;
    end;msn:[email protected]
      

  2.   

    declare 
      id_curr integer :=0;  cursor c_id is
        select id
          from test;
      begin
         open c_id;
         fetch id into id_curr;
         exit  when c_id%notfound;
         begin
         select name
           into name
           from t1
           where id = id_curr;
         exception
         when others then
         null;
         end;
    ....
      

  3.   

    把select改成cursor或者使用pl/sql sub-block
      

  4.   

    declare 
      id_curr integer:=0;
      cursor c_id is 
        select name,id from t1 where id in (select id from test);
      name t1.name%type;
    begin
      for c_id_1 in c_id loop
        SELECT NVL(C_ID_1.NAME,'NVL') INTO NAME FROM DUAL;
        IF NAME='NVL' THEN
          DBMS_OUTPUT.PUT_LING(to_char(c_id_1.id)||'处取不到数据');
        END IF;
      end loop;
    end;