这段SQL语句是什么意思,说是“去除字符串中非字母和数字字符”,但真看不懂。。。。。
declare@invarchar(50);set@i=";select@i=@i+b.cfrom(selectsubstring(a.n,iter.pos,1)ascf...
declare @i nvarchar(50); set @i=";
select @i=@i+b.c
from
(
select substring(a.n, iter.pos, 1) as c
from
(select 'as#df*4,56' as n)a,
(select id as pos from tb_num06)iter
where iter.pos<=len(a.n))b
where ascii(b.c) between 48 and 122;
select @i 展开
select @i=@i+b.c
from
(
select substring(a.n, iter.pos, 1) as c
from
(select 'as#df*4,56' as n)a,
(select id as pos from tb_num06)iter
where iter.pos<=len(a.n))b
where ascii(b.c) between 48 and 122;
select @i 展开
展开全部
ascii中数字是48-57 大写字母是65-90 小写字母是97-122
是先川建一个空的字符串,然后把字符串'as#df*4,56'的每一位都拿出来匹配他的ascii码值
在范围内的字符因为where ascii(b.c) between 48 and 122 这个条件满足会被选出来,
然后拼到空字符串上,如果不是则选出null值,也拼上去,最后打印
tb_num06这个肯定是一个1,2,3,4.。。这样的序列表,然后<=字符串长度就是10,就是10条记录
然后通过函数substring(a.n, iter.pos, 1)取出字符串的每一个字符
其实这个写的不好,无法去除逗号,冒号什么的
你可以查看下ASCII码表
是先川建一个空的字符串,然后把字符串'as#df*4,56'的每一位都拿出来匹配他的ascii码值
在范围内的字符因为where ascii(b.c) between 48 and 122 这个条件满足会被选出来,
然后拼到空字符串上,如果不是则选出null值,也拼上去,最后打印
tb_num06这个肯定是一个1,2,3,4.。。这样的序列表,然后<=字符串长度就是10,就是10条记录
然后通过函数substring(a.n, iter.pos, 1)取出字符串的每一个字符
其实这个写的不好,无法去除逗号,冒号什么的
你可以查看下ASCII码表
展开全部
准备:建立一个表: tb_num06(id int)并插入十行数据0...9
我们指接将a.n换成: 'as#df*4,56'
然后再看这一句:(select id as pos from tb_num06)iter where iter.pos<=len(a.n)将换成:(select id as pos from tb_num06)iter where iter.pos<=len('as#df*4,56'),我们转化一下为:select id from tb_num06 where id<=len('as#df*4,56'),这一句就是b,这个句子很容易理解了吧。这句话执行的话结果就是:0,1,2,3,4,5,6,7,8,9
然后再看这一句:select substring(a.n, iter.pos, 1) as c转化为:select substring('as#df*4,56', iter.pos, 1) as c,如果这样:select substring('as#df*4,56', 0, 1) as c,select substring('as#df*4,56', 1, 1) as c,select substring('as#df*4,56', 2, 1) as c.........一直到9依次输出的结果是:null,a,s,#,d,f,*,4,,,5,6,这也是这句:select substring('as#df*4,56', iter.pos, 1) as c from
(select id as pos from tb_num06)iter where iter.pos<=len('as#df*4,56')
)b的结果,如果在这句后加上where ascii(b.c) between 48 and 122,其实就是把null,a,s,#,d,f,*,4,,,5,6中的ascii码在这个范围中的选出,就选出了a,s,d,f,4,5,6,然后将这些值一一赋值给@i,然后再拼一块,这就是@i=@i+b.c,这样呢就明白了吧……但是结果是asdf456,好像没去掉数字字符啊……将48改成57就只剩下asdf了
我们指接将a.n换成: 'as#df*4,56'
然后再看这一句:(select id as pos from tb_num06)iter where iter.pos<=len(a.n)将换成:(select id as pos from tb_num06)iter where iter.pos<=len('as#df*4,56'),我们转化一下为:select id from tb_num06 where id<=len('as#df*4,56'),这一句就是b,这个句子很容易理解了吧。这句话执行的话结果就是:0,1,2,3,4,5,6,7,8,9
然后再看这一句:select substring(a.n, iter.pos, 1) as c转化为:select substring('as#df*4,56', iter.pos, 1) as c,如果这样:select substring('as#df*4,56', 0, 1) as c,select substring('as#df*4,56', 1, 1) as c,select substring('as#df*4,56', 2, 1) as c.........一直到9依次输出的结果是:null,a,s,#,d,f,*,4,,,5,6,这也是这句:select substring('as#df*4,56', iter.pos, 1) as c from
(select id as pos from tb_num06)iter where iter.pos<=len('as#df*4,56')
)b的结果,如果在这句后加上where ascii(b.c) between 48 and 122,其实就是把null,a,s,#,d,f,*,4,,,5,6中的ascii码在这个范围中的选出,就选出了a,s,d,f,4,5,6,然后将这些值一一赋值给@i,然后再拼一块,这就是@i=@i+b.c,这样呢就明白了吧……但是结果是asdf456,好像没去掉数字字符啊……将48改成57就只剩下asdf了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询