--row to column custom function, only for TABLE1 table--Paramtype is a parameter type that is used to determine that param1 and param2 are condition parametersCreate or Replace functionMy_concat (Paramtypeinch integer, param1inch varchar2, param2inch varchar2)return varchar2 isResultStrvarchar2( -);begin ifParamtype= 1 Then --Defining Cursors forTemp_cursor1inch(Selectconta_id fromTABLE1WHEREform_id=param1 andOrderType=param2) Loop resultstr:=ResultStr||Temp_cursor1. conta_id||','; EndLoop; elsif Paramtype= 2 Then forTemp_cursor2inch(SelectConta_type fromTABLE1WHEREform_id=param1 andOrderType=param2) Loop resultstr:=ResultStr||Temp_cursor2. Conta_type||','; EndLoop; elsif Paramtype= 3 Then forTemp_cursor3inch(SelectConta_weight fromTABLE1WHEREform_id=param1 andOrderType=param2) Loop resultstr:=ResultStr||Temp_cursor3. Conta_weight||','; EndLoop; End if; RESULTSTR:=RTrim(ResultStr,','); returnResultStr; End;--example of execution:Selecta.column1,a.column2,a.column3 My_concat (1, A.coolumn1,a.column2) asConta_ids, My_concat (2, A.coolumn1,a.column2) asconta_types, My_concat (3, A.coolumn1,a.column2) asconta_weights fromTABLE1 asB Left JOINTABLE2 A onA.coolumn1=b.form_id andA.column2=B.ordertype
Results such as:
Oracle Custom row-to-column function