select * from table_name 为空时,下列条件是为F,不执行 do something
if exists(select * from table_name) then
         do something
     end if;
在这里还有必要判断一个集合是否为空?

解决方案 »

  1.   

    我的意思是说在一个if语句里如何判断一个集合是否为空?其实为null与not null只是影响do something而已,我需要知道语法,具体的条件应该是什么样的,不关心。
      

  2.   

    if exists(select * from table_name) 
    这里的 exists做成一个函数 ,在函数里面判断
      

  3.   

    oracle没有这样的判断函数吗?
      

  4.   

    就是说 sql server中 exists是一个自带的函数 ,如果oracle中没有相应函数,你可以自己写一个呀
      

  5.   

    用Oracle游标
    游标的属性应该是
    游标名%found ,用它来判断是否有没有查到数据
      

  6.   

    用Oracle游标
    若是   游标名%notfound  则结果集为null
      

  7.   

    我经常这样写。
    declare a number(2)
    begin
    select 1 into a
     where exists(select * from tablename)
    exception
       when no_data_found then  //未找到数据
          a := 0
        when others then
          return -1  //数据库异常
    end;if a=1 then
      //do something
    else then
      //do something others
    end if;
      

  8.   

    用游标
    可判断%notfound,这个方法好!
      

  9.   

    如果记录数多的话游标慢
    declare 
      i integer;
    begin
      select count(1) into i from table_name;
      if i>0 then 
         dbms_output.put_line(i);
      else 
         dbms_output.put_line('is null');
      end if;
    end;