MySql SELECT语句,其中LIKE不返回结果

时间:2018-09-18 14:20:59

标签: mysql where where-clause

当我包含WHERE LIKE时,MySql语句不返回任何结果。

声明:

SELECT aes_decrypt(SchoolName, 'MyString') as SchoolName from SchoolList Where aes_decrypt(SchoolName, 'MyString') LIKE '% Part of School Name Here%'

如果我删除了LIKE,就可以了

SELECT aes_decrypt(SchoolName, 'MyString') as SchoolName from SchoolList Where aes_decrypt(SchoolName, 'MyString') = 'School Name Here'

1 个答案:

答案 0 :(得分:1)

您需要将aes_decrypt的结果强制转换为char才能使用LIKE运算符:

SELECT aes_decrypt(SchoolName, 'MyString') as SchoolName 
from SchoolList 
Where cast(aes_decrypt(SchoolName, 'MyString') as CHAR) LIKE '% Part of School Name Here%'

请参见以下示例:https://www.db-fiddle.com/f/m1ynqMzVqSs5yTeTmrqUbP/1