DISTINCT
:以外にも、与えられた順序で結果を得るために、あなたが必要とするすべてはORDER BY
句です
WITH your_data(value) AS (
SELECT 'bbb;aaa;qqq;ccc;aaa;eee' FROM DUAL
),
positions (string, lvl, start_pos, end_pos) AS (
SELECT value, 1, 1, INSTR(value, ';', 1, 1) FROM your_data
UNION ALL
SELECT string, lvl + 1, end_pos + 1, INSTR(string, ';', 1, lvl + 1)
FROM positions
WHERE end_pos > 0
),
substrings (string, substring, lvl, start_pos) AS (
SELECT string,
DECODE(end_pos, 0, SUBSTR(string, start_pos), SUBSTR(string, start_pos, end_pos - start_pos)),
lvl,
start_pos
FROM positions
)
SELECT string,
substring,
lvl
FROM substrings
WHERE INSTR(';' || string || ';', ';' || substring || ';') = start_pos;
出力:
STRING SUBSTRING LVL
----------------------- ----------------------- ----------
bbb;aaa;qqq;ccc;aaa;eee bbb 1
bbb;aaa;qqq;ccc;aaa;eee aaa 2
bbb;aaa;qqq;ccc;aaa;eee qqq 3
bbb;aaa;qqq;ccc;aaa;eee ccc 4
bbb;aaa;qqq;ccc;aaa;eee eee 6
出典
2017-05-22 07:22:47
MT0