简体   繁体   English

想知道存储过程中的split()

[英]Want to know about split() in store procedure

DECLARE @timeRange as varchar(max)
SET @timeRange= '00:30-01:00**00:20-01:00'

DECLARE @tblTime TABLE(RowNum int identity(1,1),TimeRange ntext)

INSERT INTO @tblTime SELECT rtrim(ltrim(items)) from split(@timeRange,'**')
select *from @tblTime

The above procedure is returning three rows with the middle being null 上面的过程返回三行,中间为空

And

DECLARE @timeRange as varchar(max)
SET @timeRange= '00:30-01:00*00:20-01:00'

DECLARE @tblTime TABLE(RowNum int identity(1,1),TimeRange ntext)

INSERT INTO @tblTime SELECT rtrim(ltrim(items)) from split(@timeRange,'*')
select *from @tblTime

The above code is returning two rows exactly what I wanted. 上面的代码返回的两行正是我想要的。

I'd like to know why the split() function affects my result. 我想知道为什么split()函数会影响我的结果。

I have concatenated string with ** first then split, the result is different from the string concatenated with * . 我先用**连接字符串,然后拆分,结果不同于用*连接的字符串。 EDITED: the split function is from SageFrame 编辑:拆分功能来自SageFrame

Ignoring the \\*\\* which I assume should be ** ... 忽略\\*\\*我认为应该是** ...

I guess (we don't know what the split function looks like) that the delimiter parameter is char(1) (or varchar(1) ). (我们不知道拆分函数的样子),定界符参数是char(1) (或varchar(1) )。 This means that ** is truncated to * , so you get 3 rows. 这意味着**被截断为* ,因此您将获得3行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM