[英]Getting value from database using equals while ignoring certain letters
I have a column in MYSQL named 'text', and it has one value: "He?llo?". 我在MYSQL中有一列名为“文本”,它具有一个值:“ He?llo?”。 I'm trying to get the value "He?llo?"
我正在尝试获取值“ He?llo?” where using the equal to "Hello" to get it.
使用等于“ Hello”的方式获取它。 It doesn't equal because "He?llo?"
这并不相等,因为“嘿?” has 2 question marks inside of it, and "Hello" has none.
其中有2个问号,而“ Hello”则没有。 My question is, is there a way to somehow remove the 2 question marks from "He?llo?"
我的问题是,是否有办法删除“ He?llo”中的2个问号? before comparing it to "Hello", so that it equals?
在将其与“ Hello”进行比较之前,等于吗?
$text = "Hello";
SELECT text FROM table WHERE text = '$text';
You can use replace()
: 您可以使用
replace()
:
SELECT text
FROM table
WHERE replace(text, '?', '') = '$text';
You could use replace
as many times as you like. 您可以根据需要多次使用
replace
。 But this way of proceeding will require a full table scan, and if your table has many rows this is inefficient. 但是,这种处理方式将需要对整个表进行扫描,并且如果表中有很多行,则效率很低。
There are two alternatives : 有两种选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.