Wm_concat characters more than 4000 of the processing method

Source: Internet
Author: User

When using Wm_concat or custom aggregation functions to make a string, you may encounter a result set that is larger than 4000, and the system will be prompted to exceed the system limit. So, at this point, the best way is to process the result set into the CLOB format,

There are two ways to handle the following:

1. Using functions

Type:


Create or ReplaceType str2tblType as Table  of varchar2(4000)
function:



 create  or  replace  function   Tab2clob (P_str2tbltype Str2tbltype,     
inch VARCHAR2 DEFAULT ' , ' RETURN  is  
BEGIN  
 for inch (SELECT    
 from TABLE  
ORDER  by  
L_result:=| | ||  
END LOOP;
RETURN LTrim (L_result, P_delim);
END;

Test:

Initialize data:

BEGIN
 for inch 1 10000 LOOP
INSERT  into VALUES (Sys_guid ());
END LOOP;
END;
SQL statement to test:



SELECT tab2clob (CAST as str2tbltype)) attributes
 from Ts1
WHERE <  +

Attention:

SQL statement error as follows: Due to different types

SELECT sys_util.tab2clob (CAST as str2tbltype))
 from (SELECTDISTINCT from EMP)

Will throw the following exception information:

Because VARCHAR2 is declared in Str2tbltype, but now Deptno is a number, the data type is inconsistent, so you can use To_char to see it for conversion to avoid the above error:

SELECT sys_util.tab2clob (CAST as str2tbltype))
 from (SELECTDISTINCT from EMP)

Two: SQL-supplied statements that handle XML using Oracle: Xmlagg ()

The SQL statements are as follows:

SELECT RTrim || ' , ' ORDER  by ename)
. Getclobval (),
' , ' ) attributes,
Deptno
 from EMP
GROUP  by Deptno;



reprinted from: http://blog.csdn.net/l2tp1012/article/details/30744371

Wm_concat characters more than 4000 of the processing method

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.