从 Oracle 中的多个值中获取一个值 SQL

get one value from multiple values in Oracle SQL

我尝试了下面的查询,其中 return 有两个值,但我需要得到一个用 ',' 分隔的值。例如查询应该 return 结果:

TRPT,PRLD

下面是我试过的查询:

SELECT     
    LISTAGG(T_NAME, ',') WITHIN GROUP (ORDER BY T_NAME) "ListValues"
FROM TST_TBL where T_DATE > sysdate-1 
GROUP BY T_NAME

它returns:

ListValues
    TRPT
    PRLD

删除 GROUP BY 子句,它会导致您的“问题”。

SQL> with tst_tbl (t_name, t_date) as
  2    (select 'TRPT', sysdate from dual union all
  3     select 'PRLD', sysdate from dual
  4    )
  5  SELECT
  6      LISTAGG(T_NAME, ',') WITHIN GROUP (ORDER BY T_NAME) "ListValues"
  7  FROM TST_TBL where T_DATE > sysdate-1
  8  /

ListValues
--------------------
PRLD,TRPT

SQL>