Equivalent to PostgreSQL array() / array_to_string() functions in Oracle 9i

后端 未结 2 871
我寻月下人不归
我寻月下人不归 2020-12-10 15:03

I\'m hoping to return a single row with a comma separated list of values from a query that returns multiple rows in Oracle, essentially flattening the returned rows into a s

2条回答
  •  北海茫月
    2020-12-10 15:29

    In 10g I definitely prefer the COLLECT option mentioned at the end of Tim's article.

    The nice thing about that approach is that the same underlying function (that accepts the collection as an argument), can be used both as an aggregate and as a multiset function:

    SELECT deptno, tab_to_string(CAST(MULTISET(SELECT ename FROM emp 
    WHERE deptno = dept.deptno) AS t_varchar2_tab), ',') FROM dept
    

    However in 9i that's not available. SYS_CONNECT_BY_PATH is nice because it's flexible, but it can be slow, so be careful of that.

提交回复
热议问题