Din kod fungerar inte som DUAL
tabellen har ingen code
kolumn; men om vi antar att du använder en annan tabell som har den kolumnen:
CREATE TABLE table_name ( code ) AS
SELECT '[1],[22],[333],[4444],[55555],[666666],[7777777],[88888888],[999999999],[0000000000]' FROM DUAL
Sedan kan du använda en rekursiv sub-query factoring-sats:
WITH rsqfc ( code, start_pos, end_pos ) AS (
SELECT code,
1,
INSTR( code, ',', 1 )
FROM table_name
UNION ALL
SELECT code,
end_pos + 1,
INSTR( code, ',', end_pos + 1 )
FROM rsqfc
WHERE end_pos > 0
)
SELECT DISTINCT
REPLACE(
CASE end_pos
WHEN 0
THEN SUBSTR( code, start_pos + 1, 8 )
ELSE SUBSTR( code, start_pos + 1, LEAST( end_pos - start_pos - 1, 8 ) )
END,
']'
) AS code
FROM rsqfc;
Vilka utgångar:
db<>fiol här