Create Table henry_test (a varchar2 (10), B int );
Insert Into henry_test values ('A', 1 );
Insert Into henry_test values ('bb', 1 );
Insert Into henry_test values ('cc', 1 );
Insert Into henry_test values ('dd', 2 );
Insert Into henry_test values ('ee ', 2 );
Insert Into henry_test values ('ff ', 3 );
Insert Into henry_test values ('gg ', 3 );
Insert Into henry_test values ('hh ', 3 );
Commit;
------------------------------------
Create or replace functionF_henry_ConcatRowsByColumn (
Column2Value in Varchar2, -- group the value of this column
ColumnName1 in Varchar2, -- Name of the column to be connected
ColumnName2 in Varchar2, -- Name of the Column Used for grouping
TableName in Varchar2 -- table name
)
Return varchar2Is
V_ResultVarchar2 (32767 );
Type cur_type is ref cursor;
MyCur cur_type;
V_Column1Value varchar2 (4000 );
Begin
Open myCur for 'select' | ColumnName1 | 'from' | TableName | 'where' | ColumnName2 | '=' | Column2Value;
Loop
Fetch myCur Into v_Column1Value;
Exit When myCur % notfound;
V_Result: = v_Result | v_Column1Value | ',';
End Loop;
Close myCur;
Return (v_Result );
End f_henry_ConcatRowsByColumn;