为了满足需求自定义Split()在SQL中实现,代码很整洁,感兴趣的朋友可以参考下,或许对你学习sql语句有所帮助
代码如下: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(max)
set @Index = charindex(@Separator,@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 @Input = 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
函数、表都建好了,下面调用测试一下吧:
代码如下:
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)
结果,截个图来看一下:

TodropaviewInmysql, verwenden Sie "dropviewifexistsView_name;" und tomodifyAview, verwenden Sie "creetorReplaceViewView_nameasSelect ...". WhendroppingAView, AXIZENDENDEPENTENDENSANDUSUSE "SHOWREATEVIEWVIEW_NAME;" "

MySQLViewScaneffectivItilizedEntatternSliKeadapter, Dekorateur, Factory undobserver.1) adapterPatternAdaptsdatafromDifferentTableStoaunifiedView.2) DekoratorpatternHancesDataWithokulediel.3) FactoryPatherncreat.ProduculedFeld.3) FactoryPathertoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoryPectoration

ViewSinMysqLarbenicialforSimplifyTyComplexQueries, Verbesserung der Sicherheit, Sicherstellung von Dataconsistenz und optimizierterformance.1) SimplifyComplexQueriesbyCapscapsThemintorusableViewViews.2) ViewSenhiteCurityByControllingDataAccess.3) TheenedatacocurityBycaprollingDataAccess.3) TheenedatacocurityBycaprollingDataAccess.3) TheenedatacocurityBycaperingDataAccess.3) TheenedatacocurityBycaperingDataAccess.3) TheenedatacocurityByCaperingDataAccess.3) TheenedatacocourityByCaprollingDataAccess.3) Theensedataco

ToCreateAsimpleviewInmysql, UsethecreateviewStatement.1) definessetheviewWithCreateView_nameas.2)

Tocreateusersinmysql, useTheCecreateuserStatement.1) ForAlocalUser: CreateUser'LocalUser '@' localhost'ididentifiedBy'SecurePassword ';

MySQLViewShavelimitations: 1) Sie sind supportallsqloperationen, restriktedatamanipulation ThroughviewswithjoinSuBqueries.2) Sie können sich angesehen, insbesondere mit der kompetenten Formata -Ansichten, die docrexQuqueriesorlargedatasets angezeigt werden

OrteSermanagementinmysqlisicialforenHancingSecurityAnsuringEffizienceDatabaseoperation.1) Usecreateutertoaddusers, spezifizierende Connections mit 'localhost'or@'%'.

Mysqldoes nicht imposeahardlimitontriggers, aber praktische Faktorendeterminetheireffectiveuse: 1) serverconfigurationImpactstriggermanagement;


Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

Video Face Swap
Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heißer Artikel

Heiße Werkzeuge

SAP NetWeaver Server-Adapter für Eclipse
Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

PHPStorm Mac-Version
Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool

VSCode Windows 64-Bit-Download
Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools
