嗨,我在 oracle 中有以下用于字符串聚合的函数
CREATE OR REPLACE FUNCTION STRING_AGGREGATE(i_query VARCHAR2,
i_seperator VARCHAR2 DEFAULT ',')
RETURN VARCHAR2
AS
l_return CLOB:='';
l_temp VARCHAR(32000);
TYPE r_cursor is REF CURSOR;
rc r_cursor;
BEGIN
OPEN rc FOR i_query;
LOOP
FETCH rc
INTO L_TEMP;
EXIT WHEN RC%NOTFOUND;
l_return:=l_return||L_TEMP||i_seperator;
END LOOP;
RETURN RTRIM(l_return,i_seperator);
END;
当我调用此函数时,它显示如下
SELECT STRING_AGGREGATE('select ename from emp') ENAMES FROM DUAL;
ENAMES
---------------------------
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
这个函数在这里工作得很好但是当我用带有空格的多列调用这个函数时它给了我错误这是我的查询
SELECT STRING_AGGREGATE('select ename||' Job is '||Job from emp') ENAMES FROM DUAL;
我想得到结果
smith job is clerk,allen job is accountatnt,ward job is programmer etc..
请指导我如何实现这一目标