sql把字符数组转换成表:把字符串1,2,3变成表里的行数据

sql把字符数组转换成表:把字符串1,2,3变成表里的行数据

2023年7月9日发(作者:)

sql把字符数组转换成表:把字符串1,2,3变成表⾥的⾏数据

需求:把字符串1,2,3变成表⾥的⾏数据⽅法:⽤⾃定义函数实现/* 获取字符串数组的 Table*/if exists (select 1 from sysobjects where id = object_id('Get_StrArrayStrOfTable' )) drop Function Get_StrArrayStrOfTablegoCREATE function Get_StrArrayStrOfTable( @SourceSql varchar (max), @StrSeprate varchar (10))returns @temp table( F1 varchar (100))asbegin declare @i int set @SourceSql =rtrim( ltrim(@SourceSql )) set @i =charindex( @StrSeprate,@SourceSql ) while @i >=1 begin insert @temp values(left( @SourceSql,@i -1)) set @SourceSql =substring( @SourceSql,@i +1, len(@SourceSql )-@i) set @i =charindex( @StrSeprate,@SourceSql ) end

if @SourceSql <>'' insert @temp values( @SourceSql)

returnendGO

⽤法:SELECT * from _StrArrayStrOfTable('1,2,3',',')

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688907868a182297.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信