有人能帮我解决这个问题吗?
在表"test“中有一列"x”。
X将只有一行数据= 1,2,3,4,5,7,9,11这样的数据。
我想将行转换为列,分隔符将为",“。
我有2列a,b
数据,如
A、b
[经]1 2
3 4
5 6
7 8
9 10
我希望结果是1-2,3-4,5-6,7-8,9-10(平均形式可以划)
现在我能做这个了吗?
发布于 2014-12-24 07:14:19
由于您的问题尚不清楚您是要拆分该列还是将其连接起来,因此在这里我向您提供两种解决方案:-
若要在带有分隔符的甲骨文中拆分字符串,请使用以下查询:-
select DISTINCT to_number(regexp_substr(X,'[^,]+',1,level)) numbers
from your_table
connect by to_number(regexp_substr(X,'[^,]+',1,level)) is not null
order by 1;若要连接oracle中具有多行分隔符的列的值,请使用以下查询:-
select wm_concat(X) as column_x from your_table ;这是您问题的完整演示代码,解决方案查询将给出所需的结果.
create table dumdd
(seq_id number,value varchar2(50))
insert all
into dumdd values(1,'1,2,3,4,5,7,9,11')
into dumdd values(2,'1,2,3,4,5,7,9,11')
into dumdd values(3,'1,2,3,4,5,7,9,11')
select * from dual;
commit;
select seq_id,numbers from
(
select distinct seq_id,to_number(regexp_substr(value,'[^,]+',1,level)) numbers
from dumdd
connect by to_number(regexp_substr(value,'[^,]+',1,level)) is not null
)
where seq_id=1
order by 1,2; 发布于 2014-12-24 06:30:52
你可以试试下面的方法
select distinct regexp_substr(x,'[^,]+',1,level) from table
connect by level <=regexp_count(x,',')+1;https://stackoverflow.com/questions/27632483
复制相似问题