简体   繁体   中英

MySql SELECT statement with where LIKE not returning results

MySql statement does not return any results when I include WHERE LIKE .

Statement:

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

If I remove the LIKE it works

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

You need to cast the result of aes_decrypt to char in order to use LIKE operator:

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

See this example: https://www.db-fiddle.com/f/m1ynqMzVqSs5yTeTmrqUbP/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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