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)