一个sql问题

我在cursor中写了1段select 语句来得到一些需要的字段,然后用这些字段的值作为一些逻辑验证的必要条件,但是select 出来的某些必要条件字段可能为空,那么对于这1条纪录而言就会no_data_found  我想要让程序遇到no_data_found 就跳到下一条select 中去执行,该怎么写?

cursor c is
select a,b
from table_1 t1 ;

begin
for cur in c
loop
select i,m
into ii mm
from table_2 t2
where t2.column1=cur.a
and t2.column2=cur.b      (cur.b 中的值可能为null)
dbms_output.put_line('=======显示消息=====');
end loop;
exception
...............
end;
我也来说两句 查看全部回复

最新回复

  • gavinhuang (2008-11-12 18:13:59)

    for v_record in (select a,b from table_1 ) loop
    if v_record.b is not null then
    ......
    end if;
    end loop;
    exception
    when NO_DATA_FOUND then
    null;

    [ 本帖最后由 gavinhuang 于 2008-11-12 18:15 编辑 ]
  • superrg (2008-11-12 18:29:19)

    我的意思是,我想不在上面判断是否为空,而是想在when NO_DATA_FOUND then 后让循环去找下1条,如果下1条还是NO_DATA_FOUND  再往下找,直到全部搜索结束。
  • redneck_he (2008-11-12 22:40:49)

    cursor c is select a,b from table_1 t1 ;

    begin
      for cur in c
      loop
          begin
             select i,m into ii,mm from table_2 t2
               where t2.column1=cur.a
                   and t2.column2=cur.b      (cur.b 中的值可能为null)
          exception when no_data_found then
               goto continue;
          end;
          dbms_output.put_line('=======显示消息=====');
       <<continue>>
    end loop;

    exception
    ...............
    end;