项目内需要解决主表a和明细表b的连接问题,要求将b表中的不同列部分进行合并起来;其实也是网上搜出来的解决办法,:),只要自己理解了就成为自己的知识了,:)
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;