I've found the tab_to_string from other Q/A for aggregation values. hope this can solve the problem but it seems something is not right.
CREATE OR REPLACE TYPE FMF_VERIFY5.t_varchar2_tab AS TABLE OF VARCHAR2(32767);
CREATE OR REPLACE FUNCTION FMF_tab_to_string (p_varchar2_tab IN t_varchar2_tab,
p_delimiter IN VARCHAR2 DEFAULT ',') RETURN VARCHAR2 IS
l_string VARCHAR2(32767);
BEGIN
FOR i IN p_varchar2_tab.FIRST .. p_varchar2_tab.LAST LOOP
IF i != p_varchar2_tab.FIRST THEN
l_string := l_string || p_delimiter;
END IF;
l_string := l_string || p_varchar2_tab(i);
END LOOP;
RETURN l_string;
END tab_to_string;
/
SELECT ID, tab_to_string(CAST(COLLECT(COMMENTS ORDER BY DATE DESC) AS t_varchar2_tab),'//') AS COMMENTS
FROM TABLE
Above SELECT query works time to time based on the input value. it looks like when comment has big data it throws an error.
COMMENT is varchar(1024) and there can be up to 20 comments.
You can try this query for getting a comment in clob and restrict the size to 32767.
SELECT
LENGTH(LIST),
LIST
FROM
(
SELECT
SUBSTR(RTRIM(XMLAGG(XMLELEMENT(E, COMMENT, ',').EXTRACT('//text()')).GETCLOBVAL(), ','), 1, 32767) AS LIST
FROM
MYTABLE
);
Cheers!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.