SQL statement (4)-UDF

Source: Internet
Author: User

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;

 

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.