select
substr((xmlagg(xmlparse(content t.mjzh||',')).getclobval()),1,length((xmlagg(xmlparse(content t.mjzh||',')).getclobval()))-1) 账户
from TFP_CPDM t
WHERE t.MJZH IS NOT NULL
CREATE OR REPLACE FUNCTION FUNC_COLUMNLIST(I_TABLENAME IN VARCHAR2, -- 表名
I_COLUMN IN VARCHAR2, -- 要集合的列
I_WHERE IN VARCHAR -- 自定义条件 可为空
--例如:AND ID IN(1,2,3) 或 and userid=''admin'' 或 and userid=''admin'' and id=0 …… ……
)
RETURN CLOB
IS
RESULT CLOB;
PRAGMA AUTONOMOUS_TRANSACTION;
/*
彬之栋 20210420 新增
获取某表某字段为一个值输出 逗号隔开 (WM_CONCAT_11G 本身有字符串大小限制 进行循环拼接)
*/
O_ZD CLOB;
V_COUNT NUMBER;
V_NUM NUMBER;
V_START NUMBER;
V_END NUMBER;
O_RESULT CLOB;
V_sql VARCHAR2(2000);
BEGIN
V_sql := 'SELECT COUNT(1) FROM '||I_TABLENAME||' WHERE '||I_COLUMN||' IS NOT NULL '|| I_WHERE;
EXECUTE IMMEDIATE V_sql INTO V_COUNT;
SELECT CEIL(V_COUNT/100) INTO V_NUM FROM DUAL;
-- 1--100 0*100+1 1*100
-- 101--200 1*100+1 2*100
FOR I IN 1..V_NUM LOOP
V_START := (I-1)*100+1;
V_END := I*100;
V_sql := 'SELECT WM_CONCAT_11G(A.'||I_COLUMN||')
FROM (SELECT ROWNUM RN,'||I_COLUMN||' FROM '||I_TABLENAME||' WHERE '||I_COLUMN||' IS NOT NULL '|| I_WHERE ||') A
WHERE A.RN >= '||V_START||'
AND A.RN <= '||V_END;
EXECUTE IMMEDIATE V_sql INTO O_ZD;
IF V_START = 1 THEN
O_RESULT := O_ZD;
ELSE
O_RESULT := O_RESULT || ',' || O_ZD;
END IF;
END LOOP;
RESULT:=O_RESULT;
RETURN RESULT ;
END FUNC_COLUMNLIST;