简体   繁体   English

MySQL替换多个字符

[英]MySQL replace multiple character

I need to fetch data from my MySQL database where one column is filled with strings that contains different quotes and apostrophes ( ', ', ` and the classic one ' ). 我需要从我的MySQL数据库中获取数据,在该数据库的一列中填充了包含不同引号和撇号( ',','和经典的' )的字符串。

In my search bar, I want to be able to only write the classic one ' and be able to search for that specific field wheter it contains ', ' or `. 在我的搜索栏中,我只希望写经典的',并且能够搜索包含','或'的特定字段。 For example, I'd like to write " Regie de l'Angleterre " and that it automatically checks " Regie de l'Angleterre " and so on. 例如,我想编写“ Regie de l'Angleterre ”,它会自动检查“ Regie de l'Angleterre ”,依此类推。

Is that possible ? 那可能吗 ?

How can I do something like this in SQL ? 如何在SQL中执行类似的操作? I tried to use REPLACE, but couldn't make it work with multiple 我尝试使用REPLACE,但无法使其与多个

My where clause looks like this at the moment. 目前,我的where子句看起来像这样。

SELECT realestate_name FROM realestates WHERE REPLACE(realestate_name, ''','\'') LIKE %xxx%

You can use multiple replaces in one select the Replace function returns string so you can call another one outside it. 您可以在一个中使用多个替换, select “替换”函数返回string以便可以在其外部调用另一个。 Like this 像这样

SELECT 
realestate_name 
FROM realestates 
WHERE REPLACE(REPLACE(realestate_name, ''','\''),'’','\'')  LIKE %xxx%
SELECT realestate_name FROM realestates WHERE column LIKE '____'

Before you do that, change every single ' " ` and quotation mark and space to %, and put them on the ends 在执行此操作之前,请将每个单个的“”`以及引号和空格更改为%,并将其放在最后

So it would look like this: 所以它看起来像这样:

Regie de l'Angleterre becomes: %Regie%de%l%Angleterre% Regie de l'Angleterre变成:%Regie%de%l%Angleterre%

SELECT realestate_name FROM realestates WHERE realestate_name LIKE %Regie%de%l%Angleterre%

This will work & run fine with a not so large database. 对于不太大的数据库,这可以正常运行。 If you have millions of records, LIKE becomes a nightmare. 如果您拥有数百万条记录,那么LIKE就像一场噩梦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM