SQL中代替Like语句的另一种写法
比如查找用户名包含有"c"的所有用户, 可以用use mydatabaseselect * from table1 where username like''%c%"下面是完成上面功能的另一种写法:use mydatabaseselect * from table1 where charindex(''c'',username)>0这种方法理论上比上一种方法多了一个判断语句,即>0, 但这个判断过程是最快的, 我想信80%以上的运算都是花在查找字符串及其它的运算上, 所以运用charindex函数也没什么大不了. 用这种方法也有好处, 那就是对%,|等在不能直接用like查找到的字符中可以直接在这charindex中运用, 如下:use mydatabaseselect * from table1 where charindex(''%'',username)>0也可以写成:use mydatabaseselect * from table1 where charindex(char(37),username)>0ASCII的字符即为%- 联系我们: QQ:82526114(技术) 411523648(客服) 237057746(财务)
- 电话:+86-762-4372098 邮箱:webmaster@814e.net,support@814e.net
- 粤ICP备05002242号 网监局备案:4403701910502
