oracle pl/sql results into one string

后端 未结 2 337
北荒
北荒 2020-12-21 01:23

I\'m trying to create a simple stored procedure that stores queried result into one string.

v_string1 varchar2(100);

Select column1
From dual;
相关标签:
2条回答
  • 2020-12-21 01:40

    Another option using pure SQL that will work before Oracle 11G, although is still limited to 4000 characters for the string.

    Select ltrim(max(names), ', ') as names
    From (
      Select sys_connect_by_path(name, ' ,') as names
      From (
        Select name, row_number() over (order by name) as rown
        From temp_table
      )
      Start with rown = 1
      Connect by rown = prior rown + 1
    )
    
    0 讨论(0)
  • 2020-12-21 01:45

    Using SQL Fiddle:

    select LISTAGG(name, ',') WITHIN GROUP (ORDER BY 1) AS names
    from temp_table
    
    0 讨论(0)
提交回复
热议问题