SQL里面用自定義Split()完成個(gè)性化需求建站知識(shí)
導(dǎo)讀:1建站知識(shí)為了滿足需求自定義Split()在SQL中實(shí)現(xiàn),代碼很整潔,感興趣的朋友可以參考下,或許對(duì)你學(xué)習(xí)sql語(yǔ)句有所幫助網(wǎng)站建設(shè)制作網(wǎng)站seo優(yōu)化軟件。
復(fù)制代碼 代碼如下:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE function [dbo].[SplitString] ( @Input nvarchar(max), @Separator nvarchar(max)=',', @RemoveEmptyEntries bit=1 ) returns @TABLE table ( [Id] int identity(1,1), [Value] nvarchar(max) ) as begin declare @Index int, @Entry nvarchar(網(wǎng)站建設(shè)哪家好max) set @Index = charindex(@Separator網(wǎng)站seo優(yōu)化軟件,@Input) while (@Index>0) begin set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1))) if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'') begin insert into @TABLE([Value]) Values(@Entry) end set @I網(wǎng)站建設(shè)公司nput = substring(@Input, @Index+datalength(@Separator)/2, len(@Input)) set @Index = charindex(@Separator, @Input) end set @Entry=ltrim(rtrim(@Input)) if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'') begin insert into @TABLE([Value]) Values(@Entry) end return end
函數(shù)、表都建好了,下面調(diào)用測(cè)試一下吧:復(fù)制代碼 代碼如下:
declare @str1 varchar(max), @str2 varchar(max), @str3 varchar(max) set @str1 = '1,2,3' set @str2 = '1###2###3' set @str3 = '1###2###3###' select [Value] from [dbo].[SplitString](@str1, ',', 1) select [Value] from [dbo].[SplitString](@str2, '###', 1) select [Value] from [dbo].[SplitString](@str3, '###', 0)
結(jié)果,截個(gè)圖來看一下:相關(guān)網(wǎng)站建設(shè)制作網(wǎng)站seo優(yōu)化軟件。聲明: 本文由我的SEOUC技術(shù)文章主頁(yè)發(fā)布于:2023-05-24 ,文章SQL里面用自定義Split()完成個(gè)性化需求建站知識(shí)主要講述自定義,里面,SQL網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_6655.html
為你推薦與SQL里面用自定義Split()完成個(gè)性化需求建站知識(shí)相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長(zhǎng)度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時(shí)期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12