ÏÖÓÐÒÔÏÂÊý¾Ý£º
ID Name
1 Jack,Tom,Ben
2 Mary,Simth,Tony,Jay
ת»»Îª£º
ID Name
1 Jack
1 Tom
1 Ben
2 Mary
2 Simth
2 Tony
2 Jay
ÒªÇóʹÓÃSQL²éѯÍê³É£¬ÓÉÓÚÌõ¼þÏÞÖÆ£¬²»ÄÜʹÓú¯Êý£¬¹ý³Ì£¬ÓαêÖ®ÀàµÄ·½·¨¡£
Çë´óϺÃÇ°ïæ°É£¡
SQL code:
with tt as (select 1 id,'Jack,Tom,Ben' Name from dual
union all select 2,'Mary,Smith,Tony,Jay' from dual)
select a.id,
substr(','||a.name||',',instr(','||a.name,',',1,b.rn)+1,
instr(a.name||',',',',1,b.rn)-instr(','||a.name,',',1,b.rn))name
from tt a,
(select rownum rn from dual
connect by rownum<10)b
where length(a.name)-length(replace(a.name,','))+1>=b.rn
order by id,b.rn
Õâ¸ö10Òª°´ÄãµÄʵ¼ÊÇé¿öÐÞ¸Ä
²»Ð¡ÓÚÔ±íÖÐnameÀïÏîÊýµÄ×î´óÖµ
with tt as (
select 1 id,'Jack,Tom,Ben' Name from dual
union all select 2,'Mary,Smith,Tony,Jay' from dual
)
select substr(name,
decode(rownum, 1, 1, instr(name, ',', 1, rownum - 1)+1),
instr(name, ',', 1, rownum) -
decode(rownum, 1, 1, instr(name, ',', 1, rownum - 1)+1))
from (select wmsys.wm_concat(name)||',' name from tt) a
connect by rownum <= 5 and instr(name, ',', 1, rownu