ORACLE string buffer is too small Solution

Source: Internet
Author: User

ORACLE string buffer is too small solution today we encounter a problem where the string buffer is too small because we use the ORACLE aggregate concatenation function WM_CONCAT. The error message is as follows:

1 ### Error querying database. cause: java. SQL. SQLException: ORA-06502: PL/SQL: Number or value error: String Buffer too small 2ORA-06512: In "WMSYS. WM_CONCAT_IMPL ", the SQL exception that line 30 actually reports is complicated, and it is extracted probably like this: 1 SELECT WMSYS. WM_CONCAT (distinct compname) FROM2 (SELECT * FROM3 (select newscode, compcode from T_NEWS_COMPANY_BD) A4INNER JOIN TQ_COMP_INFO C5ON. COMPCODE = C. COMPCODE) GROUP BY NEWSCODE

 

Because the number of compnames in some groups is too large After grouping by NEWSCODE, it is more than 4000 characters After splicing. ORACLE is too stupid and will not directly add ellipsis to ignore the subsequent results, instead, an error is returned. I also searched some solutions on the internet, either user-defined aggregate functions, CLOB field processing, or nested layers to filter out too many records, which is too complicated, the problem cannot be solved quickly. After thinking for a long time, I finally thought of using partition by to solve this problem. The resolved SQL statement is as follows:
1SELECT WMSYS.WM_CONCAT(DISTINCT CASE WHEN RANK < 100 THEN COMPNAME END) FROM2(SELECT * FROM3(SELECT NEWSCODE,COMPCODE,RANK() OVER(PARTITION BY NEWSCODE ORDER BY COMPCODE) RANK FROM T_NEWS_COMPANY_BD) A4INNER JOIN TQ_COMP_INFO C5ON A.COMPCODE = C.COMPCODE) GROUP BY NEWSCODE

 

This method requires a very small amount of SQL code to be modified. If you do not care about the slight performance loss caused BY the omitted fields and partition by, I personally think it is the best solution.

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.