数据如下: with testtab as (
select 1 id, '1,2,3' str from dual
union all
select 2, '2, 4' from dual
)
select * from testtab;想要达到的查询效果是
id str
1 1
1 2
1 3
2 2
2 4现在数据库里面,已经有他人建的一个函数,作用是拆分字符串,但是只是针对一个字符串的
不知道能否利用这个函数达到我的查询目的。函数使用说明如下:
select * from table(str_split('1, 2, 3'));返回
1
2
3
解决方案 »
- 从库做 rman 备份,异常缓慢。之前都是可以的
- select操作 但是数据量太大 要等很长时间 能中途取消么
- 一个基本的在存储过程中使用游标的例子,不知为何出错,请大家帮忙!
- 关于oracle10g Personal Edition下载问题
- 关于sql语句小问
- 大家帮看看这个sql语句的毛病,在线
- 急急急,SOS,ODBC问题,解决马上结贴
- 如何使用ASP给ORACLE数据库的blob字段插入图象文件同时如何通过ASP把图象调出显示在网页上?
- 哪里有personal oracle 8.0 下载?急!
- Oracle中的(+)语法
- Oracle事务必须是执行写操作的吗?
- 客户端电脑不识别oracle数据库中文字符
也可以自己拆分:
SELECT REGEXP_SUBSTR((select wm_concat(str) from testtab), '[^,]+', 1, N) COL1
FROM DUAL,
(SELECT ROWNUM N
FROM DUAL
CONNECT BY ROWNUM <
LENGTH(REGEXP_REPLACE((select wm_concat(str) from testtab), '[^,]', NULL)) + 2)
WHERE N <= LENGTH(REGEXP_REPLACE((select wm_concat(str) from testtab), '[^,]', NULL)) + 1;COL1
--------------------------------------------------------------------------------
1
2
3
2
4
select 1 id, '1,2,3' str from dual
union all
select 2, '2,4' from dual
)
SELECT DISTINCT ID,substr(col
,DECODE(LEVEL, 1, 1, instr(col, ',', 1, LEVEL - 1) + 1)
,DECODE(instr(col, ',', 1, LEVEL)
,0
,LENGTH(COL) + 1
,instr(col, ',', 1, LEVEL)) -
DECODE(LEVEL, 1, 1, instr(col, ',', 1, LEVEL - 1) + 1)) col
FROM (SELECT ID,str col FROM testtab)
CONNECT BY LEVEL <= length(translate(col, ',' || col, ',')) + 1;
with testtab as
(select 1 id, '1,2,3' str
from dual
union all
select 2, '2,4' from dual)
select DISTINCT ID, REGEXP_SUBSTR(STR, '[^,]+', 1, LEVEL) STR
from testtab
CONNECT BY LEVEL <= REGEXP_COUNT(STR, ',') + 1
ORDER BY ID数据量大就用这个写法试试,去掉distinct:
with testtab as
(select 1 id, '1,2,3' str
from dual
union all
select 2, '2,4' from dual)
select ID, REGEXP_SUBSTR(STR, '[^,]+', 1, LEVEL) STR
from testtab
CONNECT BY LEVEL <= REGEXP_COUNT(STR, ',') + 1
and id = prior id
and prior dbms_random.value is not null
ORDER BY ID
我用10G写了一个demo