我有一個表欄位存盤的資料類似這樣:
fashion scarf
mens plaid scarf
cashmere scarf for men
mens grey scarves
mens grey scarf
我需要取出這個欄位值的集合(無重復的單詞),回傳一個字串,結果是:
mens fashion plaid grey scarves cashmere scarf for men(單詞順序無所謂)
請問sql陳述句要怎么寫呀?
謝謝大家!!!
uj5u.com熱心網友回復:
先拆, 再去重, 再合并字串WITH TMP AS
(SELECT 'fashion scarf' S
FROM DUAL
UNION ALL
SELECT 'mens plaid scarf' S
FROM DUAL
UNION ALL
SELECT 'cashmere scarf for men' S
FROM DUAL
UNION ALL
SELECT 'mens grey scarves' S
FROM DUAL
UNION ALL
SELECT 'mens grey scarf' S
FROM DUAL)
SELECT LISTAGG(S, ' ') WITHIN GROUP(ORDER BY S)
FROM (SELECT DISTINCT REGEXP_SUBSTR(S, '[^ ]+', 1, LEVEL) AS S
FROM TMP
CONNECT BY LEVEL <= REGEXP_COUNT(S, '[ ]+') + 1
AND PRIOR S = S
AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/76508.html
標籤:開發
