1. 程式人生 > >oracle的函式wm_concat字元超過4000的處理辦法

oracle的函式wm_concat字元超過4000的處理辦法

當執行sql:

select wm_concat(colA) as colA from tableA

提示:

java.sql.SQLException: ORA-06502: PL/SQL: 數字或值錯誤 : 字串緩衝區太小 ORA-06512: 在 "WMSYS.WM_CONCAT_IMPL", line 30 )

wm_concat的最大長度只有4000,超過就會報錯,

兩種方法:

(1)轉clob型別

select --wm_concat(colA) as colA
rtrim(xmlagg(xmlparse(content colA || ',' wellformed) ORDER BY colA).getclobval(),',') as colA  from tableA;

(2)先轉clob,再轉varchar2,但是長度還是隻能4000

select --wm_concat(colA) as colA
dbms_lob.substr(rtrim(xmlagg(xmlparse(content colA || ',' wellformed) ORDER BY colA).getclobval(),','),4000) as colA  from tableA;


這是別人的方法:http://blog.csdn.net/l2tp1012/article/details/30744371