防止mysql在where子句中将字符串强制转换为int [英] Prevent mysql casting string to int in where clause
问题描述
我正试图防止mysql在where子句中将字符串强制转换为int。
I'm trying to prevent mysql from casting a string to an int in a where clause.
以下查询返回该订单的正确行
The following query returns the correct row for the order
从订单中选择delivery_name的订单ID ='985225'
以下查询还返回与将我的字符串强制转换为int相同的行,但是我想完全阻止它返回该行(即,不强制转换为int的字符串并有效地说,这不能准确地
The following query also returns the same row as it is casting my string to an int, but I'd like to prevent it from returning the row at all (ie, not cast the string given to an int and effectively say, this cannot accurately be cast to an int so don't).
从订单中选择delivery_name,而orders_id ='985225a'
我希望这是有道理的,任何帮助将不胜感激!
I hope that makes sense, any help would be greatly appreciated!
推荐答案
您应该可以完全避免这种情况,但是如果您想要一种解决方法,可以在字符串的前面连接一个字符,例如:
You should be able to avoid this scenario altogether, but if you wanted a workaround you could concat a character to the front of the string, something like:
SELECT delivery_name
FROM orders
WHERE CONCAT('a',orders_id) = CONCAT('a','985225a')
这篇关于防止mysql在where子句中将字符串强制转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!