select  a.leavingid into tmp_id from gs_leaving a 
    where a.leavingid = LeavingID and
          a.begintime <= to_date(datetime,'yyyy-mm-dd') and
          a.endtime >= to_date(datetime,'yyyy-mm-dd'); 
-这里返回多条记录,用游标。

解决方案 »

  1.   

    呵呵,可惜这里不能用LIMIT 要是可以就可以限定行数了。
      

  2.   

    to  welyngj(平平淡淡): leavingid这个字段是关键字,怎么会返回多行。 搞不懂Oracle
      

  3.   

    在 pl/sql中执行如下:
        select  count(*)  from gs_leaving a 
        where a.leavingid = '000008'
       结果返回如下: 1
    但是把它放在函数中它就返回(表中所有的记录数):700
      

  4.   

    (平平淡淡)说得对,建议你使用游标来解决这个问题,create or replace function GetLeavFlag(LeavingID varchar2,datetime varchar2) return integer is
     Result int;
     tmp_id varchar2(20); cursor mycur1 as select  a.leavingid into tmp_id from gs_leaving a 
                        where a.leavingid = LeavingID and
                              a.begintime <= to_date(datetime,'yyyy-mm-dd') and
                              a.endtime >= to_date(datetime,'yyyy-mm-dd'); 
    begin
      Result := 0;
      tmp_id := '';
      
      open mycur1;
      loop
        fetch mycur1 into tmp_id;
        exit then mycur1%nofound;
      end loop;  if tmp_id<>'' then Result := 1 ; --如果 tmp_id 不为空返回1
      else Result :=0 ;  --如果 tmp_id 为空则返回0
      end if  ;
      exception when no_data_found then  
        Result :=0 ;
      return Result;        
    end GetLeavFlag;