在Oracle中,可以使用不同的方法來實現在使用LISTAGG函數時去重重復的值。以下是一些常用的方法:
SELECT LISTAGG(column_name, ',') WITHIN GROUP (ORDER BY column_name) AS result
FROM (
SELECT column_name, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) rn
FROM table_name
)
WHERE rn = 1;
SELECT LISTAGG(DISTINCT column_name, ',') WITHIN GROUP (ORDER BY column_name) AS result
FROM table_name;
SELECT LISTAGG(column_name, ',') WITHIN GROUP (ORDER BY column_name) AS result
FROM (
SELECT column_name, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) rn
FROM table_name
)
START WITH rn = 1
CONNECT BY PRIOR column_name = column_name AND PRIOR rn = rn-1;
這些方法可以根據具體需求選擇合適的方式來去重重復的值。