This example shows how to search for the string “50% off when 100 or more copies are purchased” in the notes column of the titles table in the pubs database:USE pubsGOSELECT notesFROM titlesWHERE notes LIKE '50%% off when 100 or more copies are purchased' ESCAPE '%'GO
比如说我想在csdn数据库中查一个以'wyb_'打头的所有用户! 写法如下select * from user where username like 'wyb_%' 由于'_'是通配符,结果所有以'wyb'打头的数据都列出来了,而不是想要的以'wyb_'打头的所有数据! 不知要实出这样的查询该怎么办?
再看一个例子: This example uses the ESCAPE clause and the escape character to find the exact character string 10-15% in column c1 of the mytbl2 table.USE pubs GO IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytbl2') DROP TABLE mytbl2 GO USE pubs GO CREATE TABLE mytbl2 ( c1 sysname ) GO INSERT mytbl2 VALUES ('Discount is 10-15% off') INSERT mytbl2 VALUES ('Discount is .10-.15 off') GO SELECT c1 FROM mytbl2 WHERE c1 LIKE '%10-15!% off%' ESCAPE '!' GO
写法如下select * from user where username like 'wyb_%'
由于'_'是通配符,结果所有以'wyb'打头的数据都列出来了,而不是想要的以'wyb_'打头的所有数据!
不知要实出这样的查询该怎么办?
This example uses the ESCAPE clause and the escape character to find the exact character string 10-15% in column c1 of the mytbl2 table.USE pubs
GO
IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'mytbl2')
DROP TABLE mytbl2
GO
USE pubs
GO
CREATE TABLE mytbl2
(
c1 sysname
)
GO
INSERT mytbl2 VALUES ('Discount is 10-15% off')
INSERT mytbl2 VALUES ('Discount is .10-.15 off')
GO
SELECT c1
FROM mytbl2
WHERE c1 LIKE '%10-15!% off%' ESCAPE '!'
GO
where username like 'wyb!_%' ESCAPE '!'
OK!
今天只回答一个问题,
Bye.
http://www.csdn.net/expert/topic/408/408385.shtm
'%'替换任意字符串
ESCAPE 当字符串中本来包括'_'、'%'时使用
select * from user where username like 'wyb[_]%'
不够500分,再来这个贴子里领剩下的吧!:)
http://www.csdn.net/expert/topic/408/408385.shtm