王爱东 发表于 2020-7-28 11:42:47

oracle 11.1之前wm_concat超过4000错误的解决办法

oracle中。用到 wm_concat函数的时候,如果汇总的数据超过4000个汉字,则要报错误:

这是在11.2之前这个函数返回的string.

如果有这种错误,可以自己写一个函数,返回clob的方式来实现超过4000个字符的。

创建type:
create or replace type str2tblType as table of varchar2(4000);


创建函数:
CREATE OR REPLACE FUNCTION tab2clob(p_str2tbltype str2tbltype,
                      p_delim       IN VARCHAR2 DEFAULT ',') RETURN CLOB IS
                      l_result CLOB;
    BEGIN
       FOR cc IN (SELECT column_value
                  FROM TABLE(p_str2tbltype)
               ORDER BY column_value) LOOP
      l_result := l_result || p_delim || cc.column_value;
   END LOOP;
   RETURN ltrim(l_result, p_delim);
   END;

   调用函数效果:
   select tab2clob(CAST(COLLECT(tm) AS str2tbltype)) from table

页: [1]
查看完整版本: oracle 11.1之前wm_concat超过4000错误的解决办法