因此,我有下表:
ID product
1 usb-stick
2 blackberry
3 cup of tea
4 usb-stick 2.0
5 computerSELECT * FROM products WHERE product LIKE '% <value> %'但是因为有一些特殊的字符存储在我的列中,所以我必须写下实际的值,这样才能得到这些结果。
因此,我的问题是,是否有任何方法可以转义特殊字符(存储在我的列中,例如: usb-stick),以便可以搜索以下语句:
ID product title / keyword (seperated by comma) product must be searchable for
1 usb-stick usb stick, usb stick (notice the spaces)
2 blackberry blackberry, black berry
3 cup of tea cup of tee
4 usb-stick 2.0 usb stick 2.0, usb stick 2, usb-stick 2, etc
5 computer computer简而言之,我只希望产品可以搜索到其他语句(所以不仅仅是实际的值/标题)。
帮助将会被认可!
发布于 2015-08-08 21:45:37
您可以使用replace()
SELECT * FROM products WHERE replace(product , '-', '') LIKE '% <value> %'编辑,这一点都不友好,但可以工作:
SELECT * FROM products WHERE
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(product, '\"', ''),
'.', ''),
'?', ''),
'`', ''),
'<', ''),
'=', ''),
'{', ''),
'}', ''),
'[', ''),
']', ''),
'|', ''),
'\'', ''),
':', ''),
';', ''),
'~', ''),
'!', ''),
'@', ''),
'#', ''),
'$', ''),
'%', ''),
'^', ''),
'&', ''),
'*', ''),
'_', ''),
'+', ''),
',', ''),
'/', ''),
'(', ''),
')', ''),
'-', ''),
'>', ''),
' ', '-'),
'--', '-') like '% <value> %'https://stackoverflow.com/questions/31893705
复制相似问题