在做echarts地图开发的时候,为了造数据方便,研究了下将给定的字符串转换成行记录以及将多行记录拼接成json字符串。
1.字符串转多行:
select m.mc, trunc(dbms_random.value(100, 1000)) zbz
from (select substr(t, 1, instr(t, '、', 1) - 1) mc
from (select substr(s, instr(s, '、', 1, rownum) + 1) || ',' as t,
rownum as d,
instr(s, ',', 1, rownum) + 1
from (select '、宾阳县、上林县、横县、隆安县、马山县、武鸣区、邕宁区、青秀区、西乡塘区、兴宁区、江南区、' as s
from dual)
connect by instr(s, '、', '1', rownum) > 1)) m
where m.mc is not null;
2.多行记录拼成json字符串 :
select wm_concat('{name:''' || m.mc || ''',value:' ||
trunc(dbms_random.value(100, 1000)) || '}')
from (select substr(t, 1, instr(t, '、', 1) - 1) mc
from (select substr(s, instr(s, '、', 1, rownum) + 1) || ',' as t,
rownum as d,
instr(s, ',', 1, rownum) + 1
from (select '、宾阳县、上林县、横县、隆安县、马山县、武鸣区、邕宁区、青秀区、西乡塘区、兴宁区、江南区、' as s
from dual)
connect by instr(s, '、', '1', rownum) > 1)) m
where m.mc is not null;