PHP code: create table tmp5 (id number(2),name varchar2(10),code varchar2(50)); alter table tmp5 add constraint pk_tmp5 primary key (id); insert into tmp5 values (1,'aaa','c001/c002/c007'); insert into tmp5 values (2,'bbb','c001/c003'); insert into tmp5 values (3,'ccc','c008/c0011/c029/c023'); insert into tmp5 values (4,'ddd','c102/c111/c112/c144/c167'); select id, name, --rn, --code, substr(code, st, decode(ed, 0, length(code), ed - st)) code from (select id, name, code, rn, decode(rn, 1, 1, instr(code, '/', 1, rn - 1) + 1) st, instr(code, '/', 1, rn) ed from (select * from tmp5, (select rownum rn from dual connect by rownum <= (select max(length(code)) - max(length(replace(code, '/', ''))) + 1 from tmp5)))) where ed > 0 or st > 1 order by id, rn;
create table tmp5 (id number(2),name varchar2(10),code varchar2(50)); alter table tmp5 add constraint pk_tmp5 primary key (id); insert into tmp5 values (1,'aaa','c001/c002/c007'); insert into tmp5 values (2,'bbb','c001/c003'); insert into tmp5 values (3,'ccc','c008/c0011/c029/c023'); insert into tmp5 values (4,'ddd','c102/c111/c112/c144/c167'); select id, name, --rn, --code, substr(code, st, decode(ed, 0, length(code), ed - st)) code from (select id, name, code, rn, decode(rn, 1, 1, instr(code, '/', 1, rn - 1) + 1) st, instr(code, '/', 1, rn) ed from (select * from tmp5, (select rownum rn from dual connect by rownum <= (select max(length(code)) - max(length(replace(code, '/', ''))) + 1 from tmp5)))) where ed > 0 or st > 1 order by id, rn;