Monrow,
I hope you find this forum useful. As promised I have a solution for you below.
Run the script below to build and populate a table with sample data.
Once data has been loaded, run the following query
The output from this query is
This caters for any number of colon-delimited entries.
Regards
T
I hope you find this forum useful. As promised I have a solution for you below.
Run the script below to build and populate a table with sample data.
Code:
CREATE TABLE MONROW
(
A VARCHAR2(5),
B SMALLINT,
C VARCHAR2(100)
);
INSERT INTO MONROW VALUES ('code1',1,'ZE');
INSERT INTO MONROW VALUES ('code2',2,'ER:GP');
INSERT INTO MONROW VALUES ('code3',3,'SP:NS:LK');
COMMIT;
Once data has been loaded, run the following query
Code:
WITH DATA AS
(SELECT LEVEL L
FROM DUAL
CONNECT BY LEVEL <
(SELECT MAX (LENGTH (c) - LENGTH (REPLACE (c, ':', ''))) + 2
FROM MONROW))
SELECT A,B,
SUBSTR(':'||C||':',INSTR(':'||C||':',':',1,L)+1, INSTR(':'||C||':',':',1,L+1)- INSTR(':'||C||':',':',1,L)-1) INITIALS
FROM MONROW,DATA
WHERE SUBSTR(':'||C||':',INSTR(':'||C||':',':',1,L)+1, INSTR(':'||C||':',':',1,L+1)- INSTR(':'||C||':',':',1,L)-1) IS NOT NULL
ORDER BY A,L
The output from this query is
Code:
A B INITIALS
code1 1 ZE
code2 2 ER
code2 2 GP
code3 3 SP
code3 3 NS
code3 3 LK
This caters for any number of colon-delimited entries.
Regards
T