首页 > Linux操作系统 > Linux操作系统 > 关于Oracle自定义分组函数
Create Table wbq_test (a varchar2(10),b int);
Insert Into wbq_test values ('aa',1);
Insert Into wbq_test values ('bb',1);
Insert Into wbq_test values ('cc',1);
Insert Into wbq_test values ('dd',2);
Insert Into wbq_test values ('ee',2);
Insert Into wbq_test values ('ff',3);
Insert Into wbq_test values ('gg',3);
Insert Into wbq_test values ('hh',3);
Commit;
select * from wbq_test;
create or replace function f_GroupByColumn(GroupColumnValue in Varchar2)
return varchar2 is
type cur_type is ref cursor;
myCur cur_type;
v_Column1Value varchar2(20);
v_Result varchar2(2000);
begin
Open myCur for Select a from wbq_test where b=GroupColumnValue;
Loop
Fetch myCur Into v_Column1Value;
Exit When myCur%notfound;
v_Result:=v_Result||v_Column1Value||',';
End Loop;
Close myCur;
return(v_Result);
end ;
select b,f_GroupByColumn(b) from wbq_test group by b;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/6517/viewspace-145567/ ,如需转载,请注明出处,否则将追究法律责任。