SQL学习之用通配符进行数据过滤
一、Like操作符
之前介绍的所有的操作符都是针对已知值进行过滤。不管匹配一个值还是多个值,检验大于还是小于已知值,或者检查某个范围的值,其共同点是过滤中使用的值都是已知的。
但是这种方法并不是任何时候都好用。有如下代码:
select ItemId,ItemName,CheckValueNum,CheckValueString,ResultLevel from T_Check_InfoDetail
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAigAAADSCAIAAADv+ayEAAAgAElEQVR4nO1dTW8bO5blH2m8/gXedBDU8z/oRS+es2t0FiMZ2r5FkF4N0Ois5skO4AD+AW+VzWBi2QN437ssBATjr42B6U5/Zlad9zqW7DwHnoWkUom895IsslQs6hAHRolischT1/eIJVUd9fDw8PDw8J//9d8AAAAAsAaoUngemiw//vhjo/07lkSGgZJxQYzJBfx4lVzpgvCgoMQsiDG5gB+vkitdaxKeH374odH+HUsiw0DJuCDG5AJ+vEqudEF4UFBiFsSYXMCPV8mVrvaE5/pge/vgul535r5uvcUfhqrsHNIVSi6FzBTXB9tqUQandUOF2Ot0MOtw5UgrFcyO4lGajOrO87M6XKOvyIVOWWql1BxD3Szq3S1V1iQ8Hz9+1Ktm44sVYW79xB+GUst/UggPChVjq5n8dKDU4CBWYtXr6Bj0Fp4Go7rz/DycDsrhzmSsoQz+8PAgpKzwY5mpLz/h+ec//6lXtSE8TQzjYLD4xAHhQSFizCEdOhZyr5VKpl9f4WkyqvPgpyGZMQubspavTwf11jyJCM9PP91Pbz83gfv7L//48H96/5cvi2K3XyillCpeXsxq5mvHr/cuVxoU+yd7842rxb7aLotO1j+M6mCKlxe3n0f95Sq4f2zroXqsZvgH1gYixsrwqOLyZVG83OtXguSWDIaTvh5Is65O+suAv9orFu2lCKwE6i35H7TaiRbV5r5CVOfNz+3VXlGd6dVemT20ZGKZRUjKquzID/Vi/+v5cfavpuIZVKsZbOVYWjKsxsmyUkuY9nkthefzT/eT6V0TuL//8re//0Pv/2K/KPbPZ3+nd5Pp1bAohherb6lieHE3qW7MGs83roaF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xI+rO69lD0OfFPYa7Dll4YH29icLDOJAe99TuaHo3md6d7y0NsKvb63cgXVwu39p5uhVReIRKcqUiKI2wfOEWQFylrIVAUrBmiqMXW/OPTaufn7y+rewuLMID62sIT8rCU+LV03RXPNou5oEchw2l6RDkGFuqjlG/IYseq/DA+tpFeDbB+vq4V9qPjvpzT9LJ7VHPwww77nc8Ffh9VLR+fLCmeFl4zDbkakbbhVsbCWsmIFkIMcapzhjC8wDraz/hMZC38JzvF8X+2eT2ZnI5LIrheTvW18sfCK1YVjtNWHjXa8UzZlTHrCFlw2uphOtsHYL0GWs1Viu/czvcwc+pYX29scJjWl9/upl+uhn1VP+NYYateqMWra8buo/H8SqZsItLJ2P/lVPrsQI4wnJtZFFm65uyckOWO2NYX0N4YH1NQljrmMudMaUZNYSH24vTNiBZJBLqyQJPLmhGeLoEQ3g22PpaEBuXNY0pPIoqjm20lkI/QGpIJNSTBYQHwqMLD6yvASAQiDErP61n8w4hy3DShQfW1wAQCMSYlZ/Ws3mHkGU4mU8ugPU1AAQBMWblp/Vs3iFkGU668KCgoKCgoDRd/h9eD4CPiPVl6wAAAABJRU5ErkJggg==" alt="" />
需求:现在需要检索ItemName中包含"心率"的行记录,这个时候使用简单的比较操作符肯定不行,必须使用通配符。利用通配符,可以 创建 比较 特定的数据 的搜索模式,在这里如果我们想找出ItemName包含"心率"的行记录,可以构造一个通配符搜索模式:
通配符:用来匹配值的一部分的特殊字符。
搜索模式:由字面值、通配符或两者组合构成的搜索条件。
而使用通配符搜索模式,必须使用LIKE操作符,LIKE指示DBMS(数据库管理系统),后跟的搜索模式利用通配符匹配而不是简单的相等匹配进行比较。
这里上面提出的检索要求我们还没有完成,在下面介绍完通配符后再完成上面的检索任务。
二、通配符
1、百分号(%)通配符
这个通配符使我们日常开发中最常使用的通配符,在搜索串中,%表示任何字符出现任意次数(包括0次),现在我通过"%"通配符来完成上面提出的需求代码如下:
select ItemId,ItemName,CheckValueNum,CheckValueString,ResultLevel from T_Check_InfoDet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nawjChs5UUo56K8WSNiOJp/lllfVvbk1Iz/9b9r7oHGBrjexK30ftNMtrwpnAR/dgBH0g13jS0optDwFdyW/hDtHBFpXWXc9cM35ioP4IbqsBdrllleFs2A5ukhKK1SzeUnImmX/ssnOdXWMfvgYbNrC/bjjfJVB/BBdtgLtdMurwlmo6+iWHMQ58UN0pevUUre8KpyFuo5uyUGcEz9EV7pOLXXLq8JZqOvolhzEOfFDdKXr1LK3vCIjIyMjE0wn3DGBLvwyQiAQCIQIJNAEAoFQUpBAEwgEQklBAk0gEAglBQk0gUAglBT/AEsoBZmmPqQRAAAAAElFTkSuQmCC" alt="" />
ok,完成了上面的需求。
这段代码使用了搜索模式'心率%',在执行这条子句时,将检索任意ItemName列值以'心率'开头的词。%告诉DBMS(数据库管理系统)接收'心率'之后的任意字符,不管他有多少字符。
下面我们盖面上面的需求,检索ItemName列值中包含'范围'的行数据,这个时候用上面'范围%'的搜索模式就无法搜索出来,下面是解决代码:
select ItemId,ItemName,CheckValueNum,CheckValueString,ResultLevel from T_Check_InfoDetail where ItemName LIKE '%范围%'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcsAAABPCAIAAAALNnlqAAAPIElEQVR4nO2dvW4bxxbHz4sYzhOoiSBM+AYpUsTqgqi4S4OtC8OpDARxdU3KAA34AVypubgWpQuwT5eCgHFpSo2AJMqnbxXZsUhRpsBb7HJ3dj7OzO7scLmjM/hDJoezZ2b/s/PTmFrywHK5XC6X//r3f5Y+y/v3773GtywbMoxgCvmJF/KnUAnSLoj/IcJSKVHIT7yQP4VKkHatibDv3r3zGt+ybMgwginkJ17In0IlSLuIsFTKF/ITL+RPoRKkXfUR9qzfavXPyoWTj7WLVv0wgDvYJVQzi3JJnPVbsCqdYVlbFEcNO3HAXE+5Cs2BaC8+Z7Dx/uSHK8WquKiXJ+RKyTGUJUbhsFJZE2EvLi7EqnhwVV1ednGqHwZAtkJvH2FlP/PIGnYAOv2qCCLWqf0uTFiPM9h4f5bDTjrc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JZZPjGyqdGkioZquxRjoOPyrLrCkWENfpjIuz5Wf/TVuer1dPv+y3VPQa3m7AW19XmCiPsuMsgOrqcXl1OT7oMogFlkckdgjwd5blmv7fFCSvXyLtavAvl1ri0iLBGf4yEXS5fdiC7r2CY/vlreb4cfgWdl2qeEmHrnlxLYVlk+EQyLilkKIsMUs93qmxjQ1jLodIeds2yI+z5Wf/T7M6t5ff91uoS5G/n4tdA56Wipm4+EmGVoiwynBem+6XwwjceFSQs3pcyjq47XUDlkLz6SaLPdPkhbJNEWWQ4L1QwUjIOP5avlFlpQ2olQ5WDQWIqj8XZXa2fJCIsEZayyJDIT4/+1I6tBinIy4myyJDIT4/+1I6tBinIy4myyJDIT4/+1I6tBinIy4myyFChQoWKr5IRtnbYk0gkUmAiwpJIJJIvEWFJJBLJl/4Pm9gIraGA9qwAAAAASUVORK5CYII=" alt="" />
搜索模式'%范围%'表示匹配任何位置上包含文本'范围'的值,不论他之前或之后出现什么字符。
这里表示搜索ItemName列值中包含'范围'的行数据,不论它之前或者之后出现什么字符。
下面再次更改上面的需求,检索ItemName列值中以'心'开头,以'定'结尾的行数据。下面是解决代码:
select ItemId,ItemName,CheckValueNum,CheckValueString,ResultLevel from T_Check_InfoDetail where ItemName LIKE '心%定'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd8AAAA5CAIAAAD4CLYkAAAND0lEQVR4nO1dvW4bSRKuFzHsJ2AkCL16AwcbWEpXwQ0Npg4MO9rEis4kDVCAnkHJ4UxSB+gZHBBYHEUpEXC73vV6vZGoXYl/osAL5q+nf2p6fprDGVahQAx7uqurv+r+pjgcsmG1Wq1Wq3/9+z8rm3J7e2vVvqFsiBtbJYQ5LoRPIqkqXLe3t4NvPwkK7jliZxJLQpjjQvgkkqrCtWHsfN3Z2+tcpzMntzWzlr8bwDXOYqq6olxO15098KVxnhY6Ravzhmsw0lOkQNMQ7cVmlEuPT9RdyVbOol7CEJGUPqRllcRmVVIkO4/HY7HIdTqvaWdmJ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ozbEPjisCRNUDNgGTFO1q9kGZ7Fy1mM6uWgzq/Uw7Vym752ePe2xS4qYPruAf8UxDG8ARx1k6HpSN6F4HGpaUTen4F6mMmNX5WdTM41S7c5Ui9PYdXrMafLbg9PQADk+MoaggsOZMUrir2QdlsjfK/KLFgLUvsu2NYoipETuHaYUw/1KiEMJhTGHKcpyXeWLFE2ekI5mdce4WCpU1cbE08/g5oNu5qtRLLiM+3aNa7fDAy0LCr1sOjo2hqCSwxM45U3P+7KyxkBqFgT7BHOjzUGWTgNFwdkaMIxV0dfBqiUg2Ox2bYz6I27mq1EsuIz4cMl4KEiBgAkVVgd1idpb2Rhk2GbD2MNvGKO7eKGrP0t131kQlNQoDM3YO6gippZIZcXaOTVRjWVjpDHJtSGR2DTNvYLJzVZlvJmbF5/QgSjcn/jd7niDTvsLAbu99Z5Gde3XIvGdVDDunemaDuyV3sp/TE3WGuTNeKJtCsuxYO0IFHX3L1QYqRkYqyL0kzbjTYG6yc1WZv4jPik+Ig3j7LiYjqTSw2/vMhrBz1UcnslB3m6MsO1fpPEv1vHNYksu3grEZ5SD5sxYytekYUMeGOk5H6DUwouRx0F8qELctzTzDnavK+xBrRnwG37TPO+PsXG1gt/d5Z6s7VxUOAR5aDw70Zm7sKSUPGjbBTcmncOMIO+sq6y4GtjHfciV8CC4zdra5c1XhEBiGFklmhWomp4R8WbYvi2xcVyfWDu+DSV+4HXuYb7MSPgSXETtb3bmqcAiqGtoNV8Kc8CG40g1qfTtXFQ5BVUO74UqYEz4EV7pBrW/nqsIhqGpoN1wJc8KH4Eo3qLXuXEVCQkJCIoiOtUN2LvwCQkpKSkoaKLEzKSkp6Sbq/wHxxDL69dONwAAAAABJRU5ErkJggg==" alt="" />
这段代码使用了搜索模式'心%定',在执行这条子句时,将检索任意ItemName 列值以'心'开头,已'定'结尾的行数据,%告诉DBMS(数据库管理系统)接收'心'之后,'定'之前的任意字符,不管这中间有多少字符。
在使用'%'匹配的时候,需要注意的几点:
1、%几乎可以匹配任何东西,但有个例外,这就是null。
2、注意搜索模式'心%定 ',发现定后面有一个空格,而这个空格恰好改变了我们的检索的初衷,这时候DBMS回去匹配以'定 '结尾的行数据,所以在使用通配符匹配数据的时候,一定要注意空格。
2、下划线( _ )通配符
下划线(_)通配符与百分号通配符的作用一样,但他只匹配单个字符,而不是多个字符。如下代码:
select * from dbo.course where tno='t003'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPcAAACMCAIAAAAvC6gGAAAMd0lEQVR4nO2d327jNhbG+VCdgPW7DIragR8kQIHWdgDf7CsUKHZ2ak8BP0MvBhjAjnNjYNtpp9PsRTCZdPLPsZG9kCVR1KFEiqTEw5wfhIGGlqijo88UQ/Gz2BNCfpj8ixZa9BfWtWIJwju5yv/9n19ooSXKpaByr9+n6+trr/UbEVQw2Gk/maZHJJUTtpDKcz5//uy1fiOCCgY77SfT9IikcsIWUnlOUMIKKhjskMpzrq6uvNZvRFDBYEdO5mba6003bR6xjvZU/unTJ6/1GxFUMNiRk+lf5aaXr6Dyx8fd3f3Wx7Lb7f+++F+p/jcDdmAw396tTzk/HQ+Ekvvt3fqUHwqOZ10HM8u2yLc5HnDGGOOTN+PDynkx7K/Hay8pDWQpJfM8yQPjp2d+LmhyxOYq3z7ubu8efCy73f6vj38X6z8fcdafJevzPuOj2YSztORswvlkJWyzGnM2mHcajFBJUnI24YyPzh5uxZVD2Hx0ptg3rgVIZnbKZ14uaHLEEFW+3+8//PURzgVYkslIKukwmPSyHRDDk1bEzRhjLFV8jEtVMv1c0OSIFirfPt7c3vtYdvv9nx8+FupfTTifLMXNxJJkvVzSYTC38z7joxUUnrSymnA2+NlPJkNbqpLp54ImR0Si8tv1iLP+LFlPOwlyCvJtliPO+vNOg5n3M+3OBqxC5WJtsSveTOUuLqityh+2j19u7nwsu93+/R8fSvXP+ulNvf/z3Zfl+IiPl8lH2fpyfHS47acfdRfMciT0RPh4KQYpreS18R+WXlIayAIlMzn3wWs/FzQ5YnOV3z9s//ly62PZ7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jAFn8rJEUeYgk/l5IgjTMGncnLEEabgUzlBBE6DL0ZB5Q32J4jwIZUT8UMqJ+KHVE7ED6mciB9SORE/pHIifkjlRPyQyon4IZUT8UMqJ+KHVE7ED6mciB9SORE/pHIifkjlRPyQyon4IZUT8UMqJ+KHVE7ED6mciB9SORE/pHIifv4PR1pqy4Wq3nwAAAAASUVORK5CYII=" alt="" />
现在我们需要检索cname列值中SERVER 2005前面带一个空格再加上三个字符的行数据,下面是解决代码:
select * from dbo.course where cname like '___ SERVER 2005'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAAA7CAIAAADgqGEdAAAHi0lEQVR4nO1d32rbPBQ/D7UWfXmXMpaUPEhhsC9JIU8xGJQu2UWeYReFQpr2JvBt3bqu30Vpm7VN6jhsF/IfWTqypdiyLU8/RHFPlKOjo5+PZFmHwG9jWCwW5pTrolbG2I7yncm2COaaeXh4MKdcF7UyxnaU70y2RUdZB204ypaBWhljOxpL2fv7e3PKdVErY2wH78z5sNUazstq0SBl7+7uzCnXRa2MsR28M81Tlm0RlivPRPH9zc+b/9drPyn/1IEAnbG3PD8k5LDfYSQrb3l+SALB/qhqY0ZRjbjOfocAAJDBp35wcZE0+5/+uRGX1qQIzrygfgByODMzoLTFmLLPyxcTxfc3P65/emufEV70CLRH9HrcBtIbDQiEktmAkMEZU+esT6AzrtQYRgmVzAYESG/28sxeBGaT3kzy3WYVxJlRl2dGBpS2aJyym83m6sc13jFUEnGCk1RoTDgGAVjzuAu2GgBASN8mljRnmhlQ2mJM2afnlYnibzbfr649bx0LzwaEDKZsNVZCr0VJhcY8j9tAemeYedzF2YBA56MZT9atpDnTzIDSFqug7PN5j0B7RK/DuZjvT1xn2iPQHldqzLgdEXHUgRTKstqaTl89yhYxoDxlH5+WJorvby6/Xb1466R81A7nzvbH5eO0v0v6U/pRdD3t7waza/hRdcZMe8yET/pT1kjuItZG/p0acWlNCuZM2vfOsZkBpS3GlP31+Gyi+P7m6+X31YtnSL+9xthe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gsR4Kypd0c1aJWxtiOkp3pKOuQF46yZaBWxtgOR9kyUCtjbEftKCu+WCukpXSYTv9IM4Z5WRr3OG4t+Vo1pWVRj/AathkJNiojW14ijfphhUxoUFbhFEXORAm5MVhiTII/yQrSofyLEmxwZ2oeiyk8kYa3YQtoUNZ8+ofUGEStIIqMSbFB6SgWKrQvwSabslUk0gS/NBL8qMi2iTQSG/gpQulEMDMbFnbEM1CfVIg4cNJNOWQo0yOrL42R2BnpraIsZ1XhCTaYM8MvCzda9hHvrOmcp6wkK+HlrE8g369rSFjCGhjMDUo9zJf+kRrykycQRQakT/QyPayAvUNRIdtTjsY6GhCD1Dmk7OHMKKtO2XlRiTT5+SqlLDbqejflVmsEpVUKcqx7Pp+jVFLQI6vPLwDsS7ApkLLpXUCbQ7ISpj0CRfwUjDplS0j/UFtY06aSvodWt9vKXssietSmdQsTbIpey+o1J1B21IGCflBFfWGg8oDJfG2b9A8ZZRM3eKSY3TGQBSsVPfoPT/OhBQk2hewYMM1pRlkukea4nVgl7fZmeRJpJDYgO7+m0z9SoiySGJOQtobDLr6IFHnCfcAvOhuSYCNxZiMSaVLsKBk5jZlMcr1VaRgqfvtlNJGmzI6lo1bG2I6KKWs0kabMjqWjVsbYjoopazSRpsyOpaNWxtiOiilrNJGmzI6lo1bG2I6KKbt9coODQyngGOyS+Bwsg6Osg2VwlHWwDH8AM4TYSbSIoVIAAAAASUVORK5CYII=" alt="" />
ok,完成需求.这里一共三个下划线,刚好匹配了三个字符,一个不多一个不少,且这三个字符位于cname列值的开头.如果前面还有字符,像 SQL SERVER 2005,前面还有一个空格,这样的数据就无法匹配到!
注意:这里的空格问题,不能多也不能少!
3、方括号([])通配符
方括号( [] )用来指定一个字符集,他必须匹配指定位置(通配符的位置)的一个字符(也就是说必须指定通配符的位置,也就是需要检索的字符的位置)。代码如下:
select * from dbo.student
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADaCAIAAABy7arqAAATfUlEQVR4nO1d3W4b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q6keiKhMFAIvIzhWyQYx1KhhlMkFN6WyDHVhTVuxxcHyPmUzikHQyQU7g2ZUCo4SCjcG0ZBKRIKp8QoKEUg+GNLqTQUJgweRClCYBClCIFBlCIEBlGKEBhEKUJgEKUIgUGUIgQGUYoQGEQpQmD8H3ovePmPU8OzAAAAAElFTkSuQmCC" alt="" />
现在我们需要检索出sname列值中以'张'或'王'开头的学生,下面是解决代码:
select * from dbo.student where sname like '[张王]%'
select * from dbo.student where sname like '%[张王]%'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAL4AAAA8CAIAAABXbpcZAAAG7UlEQVR4nO1c227bOBCdj0oDNv9SFJGDfEiBAqnsAPmKAMV2G7kF8g19CFCsL3kJsL232Yegjpv4FhnaB1ESLYoURWkmSsADIqDH9pwhdTSiqIkhiqK//n7vmmtVG8TSiTAxnU5R/beNVwZxJDR0TjoUcNKxxPX1Nar/tvHKII6Ehs5JhwJOOpZw0nHSscRkMkH13zZeGcSR0NBRSOf379+o/tvGK4M4Eho6Lp27u3C+WGG0MFz/uvwv53/UewoAAMB65/PxIWOH3U5sgE5/NV+s5uNDxg17ASFvkLzklvEhY3sdFn/lXZcl392I8Gl3XC8SmXfDPwA7HBkzmtDlXuY8B50NRh6P1Lh0VnfhbL7EaGG4/vHz16b/vgd7wXw5G/UY7AWjHgPwguUstrDecH7uM24Zdhl0+lS8gofYMuoxYP4o/krS4REyf6T4btVIZF5hBqoyGtDlXhZ4DjrAuv0shqKGLp31ev39x89N/+d+fPp2z/MTkR6wnIWGl89meq4LkeQ64scAAJKpt4tEw1ud0YBOmocCz30PQH/SJtJZ3d3OFhgtXK+/ff9Z6P/EA4DOybDHWG8QG+O+bKHhnfU9YP6wKJJcZ9hj0DlpKhINb3VGAzppHmTPwx4DAO3M34d0hj3GZ2rsM+YH8iEc+wy8YHE7Wwx8Bl6firfvpZMYdEAjHSHC27KDWh7JUOLN+a/CaDTwDXbZM7eceMD8cYl0lqu7m9s5RgvD9Zev33P+B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qlQtGvISbP+oIimY5IIhN0YnAjfrpLAfRBRF5tIRVMG7sqVKKDWlk8sx1inHMBI+MnnI1aGiazaVlhaYruaL8y5T/oylYYFpIXdaNx+LQVRF3Jct2XcMHizXl47YgRrPRw0i4VmnYMjVUUqXG4JdBiqtElwOuwysfghSrBIsok5OKjlVa6ST/cNA+WX0AUknLfh6PNKprxu1dHgCKZwppXQ2v6+f2TrL5PQzkSCdnIbMUboeSGeBQDqN6CbSVwkOfKb/DUvzKkFNBKf7yb2EyVpHQB3pbEyBNuuoBFQJmkjyBaaYa50UdU6DzEmkkk7QgdqlpTrpZHOmvp+SLMJVKrt0qfAALlhSgSnZHVZU+yZLWWD6NvlNyxiqn7E0LDAt5M4tkyOzTQ7z+sv2S0dfYEqwr2OXRLmHiKTA1C64mmi/dJBQutZpZLlDVGBqEVl91NzeoFnrYEA/cNVbVVmICkyrhtUI3DMsVBAVmBKMRIaTDiqICkwJRiLDSQcVdAWmDo8MXDoEInV4ZHDScbDE/1E2fXEqa5D7AAAAAElFTkSuQmCC" alt="" />
这个搜索模式使用了两个不同的通配符,[张王]匹配方括号中的任意一个字符,他也只能匹配单个字符,任何多于一个字符的名字(也就是说你想用[]通配符检索sname列值为'李波'的是无法匹配的)都不匹配,%通配符匹配单个字符之后的任意数字的字符(包括0个)。
现在我们变下需求,我们需要检索sname列值中除了姓张和姓王之外的所有学生的姓名,和上面的需求刚好相反,下面是解决代码:
第一种方法:使用not操作符
select * from dbo.student where sname not like '[张王]%'
第二种方法:使用^前缀
select * from dbo.student where sname like '[^张王]%'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAACxCAIAAAAQ3lVzAAARZ0lEQVR4nO1d224btxbdH9UYjP8lKCIZ/pAAAVJJBvIVAQLXsRQD/oY8BAiOLfklwGnTpm3OQ1HHjS3bkTHnYS6ihrfNy+bQHi4IxohDce3ZWrNnNFxhYP/gKL/yK+AL9g+OCkpcXFyQjp8aLwaRY4tMlyXVAbKkvPD161fS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dc4nDACAjebdGIXbPQkkhaxV8auUaMQzm+096KJIaj5h6xWFvVSlOB6zUbjuGV5SheleiuKKgImtRFg9GekC6qnQuDp5i3BnKwoXwjuCeym+UYWYVSq4nvR0JfhzyYOn4lIuUg1sctLtisIVOPEQ/OITG4sOq5RogEZYot3pNhHqNlFpFH4zqPPX3YrCdXP451LNtmqD7y9t94EqNtEorF5jOAAdD+Cu+A4UPFc2CusaNW8pYiOC8V4q4O3UeTYKF4qcqtJKe+GjAfJ5SmuXM1c2CneARCRFxJWNwh2gF5LKRuGY6IWkMjKCoCgK2D84iibhjD4gSyojMLKkMgIjSyojMLKkMgLj/3peuXImabk4AAAAAElFTkSuQmCC" alt="" />
结果都是一样!
通配符虽然好用,但是我们使用这种功能也是有代价的!
(1)通配符搜索比其他的操作府搜索耗费的时间更长!
(2)在确实需要使用通配符时,尽量不要把他们用在搜索模式的开始,因为把他至于搜索模式的开始,搜索起来是很慢的!
(3)注意通配符的位置,如果放错地方,可能不会返回想要的数据!
SQL学习之用通配符进行数据过滤的更多相关文章
- SQL学习笔记六之MySQL数据备份和pymysql模块
mysql六:数据备份.pymysql模块 阅读目录 一 IDE工具介绍 二 MySQL数据备份 三 pymysql模块 一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测 ...
- SQL学习笔记四之MySQL数据操作
阅读目录 一 介绍 二 插入数据INSERT 三 更新数据UPDATE 四 删除数据DELETE 五 查询数据SELECT 六 权限管理 一 介绍 MySQL数据操作: DML =========== ...
- 【SQL必知必会笔记(3)】SELECT语句的WHERE子句数据过滤操作
上个笔记主要介绍了利用SELECT语句检索单个/多个/所有列,并利用DISTINCT关键字检索具有唯一性的值.利用LIMIT/OFFSET子句限制结果:以及利用ORDER BY子句排序检索出的数据,主 ...
- SQL学习之高级数据过滤
一.高级数据过滤之IN操作符 IN 操作符用来指定条件范围,范围中的每个条件都可以进行匹配.IN取一组由逗号分隔.括在圆括号中的合法值.代码如下: select ItemId,ItemName,Che ...
- SQL 必知必会·笔记<3>过滤数据
在同时使用ORDER BY 和WHERE 子句时,应该让ORDER BY 位于 WHERE 之后,否则将会产生错误 WHERE子句操作符 范围值检查 使用BETWEEN 操作符,示例: SELECT ...
- Python学习---Django误删除sql表后,如何创建数据
误删除sql表后,怎么创建数据? 仅仅适合单表,多表因为涉及约束, python mangage.py makemigrations --> 生成migrations目录和根数据库对应的sql ...
- 详实的SQL学习笔记
写在前面:最近在上海找工作,前前后后面试了N家单位,发现各个公司对程序员的数据库知识尤其是SQL语句的掌握程度有很高的要求,作为一名光荣的程序员,不会玩儿SQL语句走在街上根本不好意思和人打招呼!好了 ...
- TERADATA SQL学习随笔<一>
此博客内容简介及目录 http://www.cnblogs.com/weibaar/p/6644261.html 最近在TERADATA环境学习SQL.在这里记录一下学习中查过的知识点,作为备案. 目 ...
- MySql必知必会实战练习(三)数据过滤
在之前的博客MySql必知必会实战练习(一)表创建和数据添加中完成了各表的创建和数据添加,MySql必知必会实战练习(二)数据检索中介绍了所有的数据检索操作,下面对数据过滤操作进行总结. 1. whe ...
随机推荐
- C语言的本质(8)——副作用与顺序点
C 语言中,术语副作用是指对数据对象或者文件的修改.例如以下语句 var = 99; 的副作用是把 var 的值修改成 99.对表达式求值也可能产生副作用,例如: se = 100 对这个表达式求值所 ...
- ckeditor编辑器在java项目中配置
一.基本使用: 1.所需文件架包 A. Ckeditor基本文件包,比如:ckeditor_3.6.2.zip 下载地址:http://ckeditor.com/download 2.配置使用 A.将 ...
- Redis事务和分布式锁
Redis事务 Redis中的事务(transaction)是一组命令的集合.事务同命令一样都是Redis最小的执行单位,一个事务中的命令要么都执行,要么都不执行.Redis事务的实现需要用到 MUL ...
- magento 获取attribute的所有option
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'color');if ($attr ...
- DB_Links创建际删除
创建 create database link gadata0008 connect to gadata0008 identified by "gold" using 'ORA11 ...
- 在sql数据库变量中保存单引号的办法
set @strWhere=' AccountName like '+'''%'+@Condition+'%''' 先用'+''''+要在单引号里的内容+''''. 就这样就行了. 主要就是用三个单引 ...
- Sql Service存储过程分页
一起是用oracle数据库..感觉oracle数据库强大.查询速度是杠杠的.换了家公司用的是SQL SERVICE.以前用了1年现在捡回以前的记忆.动手写了动态SQL过存储过程分页.感觉和oracle ...
- sql server 存储过程、事务,增删改
CREATE procedure [dbo].[sp_TableSave] @TypeID tinyint, -- 0 新增,1 修改,2 删除 @ID int, ), ), ), @UID int, ...
- win7 64位系统调试zkemkeeper.dll出错误解决
最近调用中控科技dll文件总是会出现上问题,网上找了大半天都没解决? 今天终于解决,原来是旧的dll文件是有问题,在中控网站上下载了最新的sdk(64位),解压,找到sdk的全部文件夹. 全选所有的: ...
- Jexus下配置多个站点
一.在jexus中一个配置文件就是一个站点,有多少个配置文件就可以创建多少个站点 配置文件所在的位置 在siteconf中有一个最基本的配置 default ##################### ...