In order to be able to use the LISTAGG function with the collection, the collection must be declared as a nested table not as an associative array and must be created as a sql type (schema object), since it is not possible to use the pl / sql type in a select expression. To do this, you can do the following:
--- create a nested table type SQL> create or replace type t_tb_type is table of number; 2 / Type created --- and use it as follows SQL> select listagg(column_value, ',') within group(order by column_value) res 2 from table(t_tb_type(1,2,3)) -- or call the function that returns data of 3 / -- t_tb_type type RES ------- 1,2,3
Otherwise, loop is your only choice.
source share