sql 如何以逗号为分隔符分割一个字段的值 10

写了个sql分割,感觉写的超级复杂。有没有简单的方法?toad不支持split函数。。。。SELECTosys.DOWNLOADFLOWLIST,SUBSTR(osys.... 写了个sql分割,感觉写的超级复杂。有没有简单的方法?toad不支持split函数。。。。
SELECT osys.DOWNLOADFLOWLIST, SUBSTR (osys.DOWNLOADFLOWLIST, 0, INSTR (osys.DOWNLOADFLOWLIST, ',', 1) -1) AS time1,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,2) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 1)-1) AS time2,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 2)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,3) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 2)-1) AS time3,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 3)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,4) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 3)-1) AS time4,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 4)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,5) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 4)-1) AS time5,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 5)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,6) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 5)-1) AS time6,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 6)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,7) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 6)-1) AS time7,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 7)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,8) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 7)-1) AS time8,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 8)+ 1, INSTR (osys.DOWNLOADFLOWLIST, ',', 1,9) -INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 8)-1) AS time9,SUBSTR (osys.DOWNLOADFLOWLIST, INSTR (osys.DOWNLOADFLOWLIST, ',', 1, 9)+ 1 ) AS time10 FROM OTT_STB_VIDEO_ALARM osva INNER JOIN ott_systeminfo osysON osys.id = osva.SYSTEMINFO_ID WHERE osva.alarm_id = 3950;
展开
 我来答
badkano
推荐于2017-09-26 · 知道合伙人体育行家
badkano
知道合伙人体育行家
采纳数:144776 获赞数:885369
团长

向TA提问 私信TA
展开全部

可用substring函数。

创建测试表及数据:

create table test
(id varchar(10));

insert into test values ('123abc');
insert into test values ('456def');
insert into test values ('789ghi');

执行:

select substring(id,1,3) +','+substring(id,4,3) as id from test

结果截图:

也就显示成了用逗号分隔的样子。

乐乐爱知道
2015-04-25 · TA获得超过938个赞
知道答主
回答量:335
采纳率:100%
帮助的人:103万
展开全部
create function f_split(@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin

while(charindex(@split,@c)<>0)
begin

insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
go

select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',')
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
jxlykm
2014-03-28 · 超过12用户采纳过TA的回答
知道答主
回答量:58
采纳率:0%
帮助的人:39.2万
展开全部
create function f_split(@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin

while(charindex(@split,@c)<>0)
begin
insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
go

select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',')
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2014-03-28
展开全部
用charindex
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式