Home >Database >Mysql Tutorial >sqlserver 字符串分拆 语句

sqlserver 字符串分拆 语句

WBOY
WBOYOriginal
2016-06-07 17:59:26891browse

sqlserver下字符串分拆实现语句,大家可以参考下。

代码如下:
-->Title:生成測試數據
-->Author:wufeng4552
-->Date :2009-09-21 09:02:08
if object_id('f_split')is not null drop function f_split
go
create function f_split
(
@s varchar(8000), --待分拆的字符串
@split varchar(10) --数据分隔符
)returns table
as
return
(
select substring(@s,number,charindex(@split,@s+@split,number)-number)as col
from master..spt_values
where type='p' and numberand charindex(@split,@split+@s,number)=number
)
go
select * from dbo.f_split('11,2,3',',')

/*
col
----
11
2
3
(3 個資料列受到影響)
*/
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn