Oracle Custom row-to-column function

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.