首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教存储过程中,可以实现上面的功能吗

2012-08-16 
请问存储过程中,可以实现下面的功能吗?参数a http://a.com/1.jpg||http://a.com/2.jpg||http://a.com/4

请问存储过程中,可以实现下面的功能吗?
参数a = 'http://a.com/1.jpg||http://a.com/2.jpg||http://a.com/4.jpg||http://a.com/8.jpg||http://a.com/10.jpg||http://a.com/11.jpg'

可以得到a里有多少个图片地址吗? 如何得到?

[解决办法]
select (len(@s)-replace(@s,'||',''))/len('||')
[解决办法]

SQL code
DECLARE @a VARCHAR(200) = 'http://a.com/1.jpg||http://a.com/2.jpg||http://a.com/4.jpg||http://a.com/8.jpg||http://a.com/10.jpg||http://a.com/11.jpg'SELECT (len(@a)-LEN(REPLACE(@a,'||','')))/2+1/*6*/
[解决办法]
SQL code
DECLARE @A VARCHAR(1000)SET @a = 'http://a.com/1.jpg||http://a.com/2.jpg||http://a.com/4.jpg||http://a.com/8.jpg||http://a.com/10.jpg||http://a.com/11.jpg'SELECT (LEN(@A) - LEN(REPLACE(@A,'http',''))) / 4(No column name)6 

热点排行