0
我目前正在使用函数拆分以分号分隔的字符串。该功能无法分割长度为12 000个字符的字符串。它运行几分钟,然后SSMS冻结。T-SQL - 拆分字符串函数
你能否给我建议我的功能,这是能够处理这个?我会尽快发布我使用PC的功能。
谢谢。
功能(现在按预期工作):
/* fce SplitList start */
Declare @CommaDelimitedFieldNames Varchar(MAX)
Declare @CharToFind VarChar(10)
Set @CommaDelimitedFieldNames = REPLACE(@String,' ','')
Set @CharToFind = ';'
Declare @Tbl_FieldNames Table
(
Position Integer Identity(1,1),
FieldName VarChar(8000)
)
Set @CommaDelimitedFieldNames = @CommaDelimitedFieldNames + @CharToFind
Declare @Pos1 Int
Declare @pos2 Int
Set @Pos1=1
Set @Pos2=1
While @Pos1<DataLength(@CommaDelimitedFieldNames)
Begin
Set @Pos1 = CharIndex(@CharToFind, @CommaDelimitedFieldNames,@Pos1)
Insert @Tbl_FieldNames Select Cast(Substring(@CommaDelimitedFieldNames,@Pos2,@[email protected]) As NVARCHAR(MAX))
Set @[email protected]+1
Set @Pos1 = @Pos1+1
End
/* fce Splitlist end */
Sql Server对可存储在varchar(字符串数据类型)中的字符数有限制。 在尝试使用TSQL之前,您必须检查您的CSV字符串的长度。 http://stackoverflow.com/questions/7611394/maximum-size-of-a-varcharmax-variable – DhruvJoshi
谢谢你的回答。我使用NVARCHAR(MAX)来声明变量。它返回整个字符串 - 不会丢失字符。我将发布我使用的功能。问题必须在函数本身。 – Rutz
你怎么分裂?它可能是你使用的函数,它只支持varchar(4000)或其他东西。关于脱口而言 - 在数据库中拆分这样的字符串看起来像使它工作,它不应该这样做:) –