SQL> create table t as
2 select 'w,w,w,w,w,nw,nw' tag from dual
3 union all
4 select 'w,w,nw,nw,w,nw,nw' tag from dual
5 union all
6 select 'nw,w,nw,w,w,nw,w' tag from dual;
Table created.
SQL>
SQL>
SQL> with comma_pos as
2 (
3 select
4 tag,
5 instr(tag,',',1,1) i1,
6 instr(tag,',',1,2) i2,
7 instr(tag,',',1,3) i3,
8 instr(tag,',',1,4) i4,
9 instr(tag,',',1,5) i5,
10 instr(tag,',',1,6) i6
11 from t
12 ),
13 day_format as
14 (
15 select tag,
16 rtrim(case when substr(tag,1,i1) = 'w,' then 'Su/' end||
17 case when substr(tag,i1,i2-i1) = ',w' then 'M/' end||
18 case when substr(tag,i2,i3-i2) = ',w' then 'Tu/' end||
19 case when substr(tag,i3,i4-i3) = ',w' then 'W/' end||
20 case when substr(tag,i4,i5-i4) = ',w' then 'Th/' end||
21 case when substr(tag,i5,i6-i5) = ',w' then 'F/' end||
22 case when substr(tag,i6) = ',w' then 'Sa' end,'/') day_tag
23 from comma_pos
24 )
25 select tag, day_tag from day_format;
TAG DAY_TAG
----------------- -----------------
w,w,w,w,w,nw,nw Su/M/Tu/W/Th
w,w,nw,nw,w,nw,nw Su/M/Th
nw,w,nw,w,w,nw,w M/W/Th/Sa
3 rows selected.