日期:2014-05-17  浏览次数:20715 次

急!哪位高手帮忙把这个函数由SQL转为Oracle的版本
Create Function Union_TIMECARDDATA(@ID nvarchar(40),@Date Varchar(10))
Returns Varchar(1000)
As
Begin
Declare @S Varchar(1000)
Set @S=''
Select @S=@S+TimeCardTime+',' From ATDTIMECARDDATA Where PERSONID=@ID And TimeCardDate=@Date Order By PERSONID,TimeCardDate,TimeCardTime
Return(Left(@S,Len(@S)-1))
End
GO

------解决方案--------------------
SQL code

create or replace function Union_TIMECARDDATA(v_ID nvarchar2,v_Date Varchar2)
return varchar2
as
 v_s varchar2(1000);
begin
  v_s := '';
  for rec in(Select TimeCardTime From ATDTIMECARDDATA 
             Where PERSONID=v_ID And TimeCardDate=v_Date 
             Order By PERSONID,TimeCardDate,TimeCardTime 
            )
  loop
    v_s := v_s||rec.TimeCardTime||',';  
  end loop;
  v_s := substr(v_s,1,length(v_s)-1);
  return v_s;
end;
/