我创建了一个加密表。我试图在表中搜索特定字符串,无论情况如何,但我无法使其工作
要搜索的字符串(员工)
select aes_decrypt(category, 'salt') from testtable where aes_decrypt(category, 'salt') like 'Staff'
以上查询有效
select aes_decrypt(category, 'salt') from testtable where aes_decrypt(category, 'salt') like 'staff'
以上查询不起作用。无论案例如何,我如何搜索“员工”
答案 0 :(得分:0)
看起来你的解密结果会给你一个二进制字符串,这会在比较中引起区分大小写。
你可以:
select aes_decrypt(category, 'salt')
from testtable
where LOWER(aes_decrypt(category, 'salt') ) like LOWER('staff')
更优雅的解决方案是使用here所述的collate
。
答案 1 :(得分:0)
将值转换为latin1解决了区分大小写的搜索问题。
select aes_decrypt(category, 'salt') from testtable where convert(aes_decrypt(category, 'salt') using latin1) like 'staff'