您好我有以下的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..
請指導我如何實現這一目標
請提供有關錯誤的精確信息 - 錯誤代碼,錯誤消息等。 – krokodilko
錯誤消息是ora:00907 mi右括號 – user1837746
errormessage有點誤導 - 在'ename'之後和'從'emp'之前沒有撇號 - 嘗試這個查詢:'SELECT STRING_AGGREGATE('select ename'||'Job'|| ||' 'FROM emp')ENAMES FROM DUAL;' – krokodilko