create or replace function get(p_id in varchar2) 
return varchar2 
is
Result varchar2(100);
 
 cursor rad_cursor(v_id varchar2) is
        select name from b 
        where id=v_id ; 
v_count Number;  
begin
v_count:=0;
Result:='';
   for v_sor in rad_cursor(p_id) loop
    if v_count=0 then
       Result:=v_sor.name;
       v_count:=v_count+1;
     else
     Result:=Result||','||v_sor.name;
     
    end loop; 
   return(Result);
end get;
/select id,get(id) name from b group by id;

解决方案 »

  1.   

    to  beckhambobo(beckham):
    一条SQL肯定出不来吗?
      

  2.   

    strUnitOldName varchar2(100);在定义上少了分号啊.
    呵呵,少了句end if;
    还有unit_id是什么类型?CREATE OR REPLACE FUNCTION GetUnitOldName(Unit_ID in varchar2)
    return varchar2
    is
    strUnitOldName varchar2(100);cursor Unit_cursor(u_id varchar2) is
    select Unit_Name as Name from T1903 where Unit_id=u_id and Name_Order<>'1';
    Unit_Num Number;begin
    Unit_Num:=0;
    strUnitOldName:='';
       for Unit in Unit_cursor(Unit_ID) loop
        if Unit_Num=0 then
           strUnitOldName:=Unit.Name;
           Unit_Num:=Unit_Num+1;
         else
         strUnitOldName:=strUnitOldName||','||Unit.Name;
         end if;
        end loop; 
       return(strUnitOldName);
    end GetUnitOldName;
      

  3.   

    end GetUnitOldName;
    上面这句可以写成end;吗?
    有什么区别
      

  4.   

    select tt.code,decode(name1,null,'',name1)||decode(name2,null,'',','||name2)||decode(name3,null,'',','||name3)||decode(name4,null,'',','||name4)||decode(name5,null,'',','||name5)||decode(name6,null,'',','||name6) as Result from (
    select code,max((case when orde=1 then name end)) name1 ,
                max((case when orde=2 then name end)) name2,
                max((case when orde=3 then name end)) name3,
                max((case when orde=4 then name end)) name4,
                max((case when orde=5 then name end)) name5,
                max((case when orde=6 then name end)) name6
    from test 
    group by code )  tt