加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver 中charindex/patindex/like 的比较

发布时间:2020-12-12 09:42:52 所属栏目:MsSql教程 来源:网络整理
导读:一、测试环境: 1。数据库:Sql Server 2008 2。测试表:15000记录,char类型主键,无其他索引 3。测试字段:ntext 类型,最大数据长度12000 二、测试语句: 1。select * from ProductTemp where ProductDesc like '%192.168.70.236%' 2。select * from Prod

一、测试环境:

1。数据库:Sql Server 2008 2。测试表:15000记录,char类型主键,无其他索引 3。测试字段:ntext 类型,最大数据长度12000

二、测试语句:

1。select * from ProductTemp where ProductDesc like '%192.168.70.236%' 2。select * from ProductTemp where charindex('192.168.70.236',ProductDesc)>0 3。select * from ProductTemp where patindex('%192.168.70.236%',ProductDesc)>0

三、测试结果:

1。效率测试结果: charindex > like > patindex ,效率差大概20% 2。适用性测试结果: 1)charindex对于检索结果最大位移有要求,经测试,Sql2008中的ntext字段,位移不能超过3987,否则返回0; 2)patindex 和 like 无位移限制; 3)patindex 支持匹配表达式,可以应用正则; 4)like可以用'%oldstring%'进行模糊匹配; 5)charindex只能匹配固定字符串

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读