Oracle column Merge

Source: Internet
Author: User

On many occasions, we will need to use Oracle column merging, and Oracle provides methods for merging multiple rows of data from a column into a single row.

First, 10G before using Wmsys.wm_concat
Wmsys.wm_concat separates the values of the fields with ",".
Select Id,wm_concat (name) from the Tab_name group by ID;

Second, Sys_connect_by_path
Sys_connect_by_path (field name, connection symbol between 2 fields), the connection symbol here do not use commas, Oracle will error, if you must use, you can replace with replace, the method is as follows replace (field name, the original character, ', '). This function must first be built with a tree, otherwise useless.

Third, 11G after the use of Listagg
Select Listagg (ID, ', ') within group (order by ID) col_name from tab_name;

Iv. Custom Functions
Create or Replace function GetRow (table1 varchar2, ptdb1 varchar2) RETURN VARCHAR2 is
Result VARCHAR2 (1000);
Begin
For cur in (SELECT audit_code from sys_audit_column t2 WHERE table1 =
T2.table_name and ptdb1 = t2.ptdb_name) LOOP
RESULT: = result| | cur.audit_code| | ', ';
END LOOP;
Result:=rtrim (RESULT, ', ');
return (Result);
End GetRow;
(quoted from the network, I did not verify)

Related Article

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.