Like 谓词在 SQL 中如何工作? [英] How does the Like predicate work in SQL?

查看:14
本文介绍了Like 谓词在 SQL 中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 OrderNumber 的字段,并且已经有一条该字段值为JY8023"的记录.

I have a field called OrderNumber and there's already a record with that field value of "JY8023".

我尝试使用此 SQL 代码进行查询,但没有返回任何内容.

I tried querying using this SQL code, but it returned nothing.

SELECT .... WHERE OrderNumber LIKE "JY8023"

我也尝试过使用通配符,效果很好

I also tried using wildcards and it worked

SELECT .... WHERE OrderNumber Like "%JY8023%"

这是否意味着 OrderNumber Like "JY9023"OrderNumber = "JY8023" 不同?

So does that mean OrderNumber Like "JY9023" is not the same as OrderNumber = "JY8023"?

推荐答案

字符串前后有字符,你看不到.尝试类似 select length(OrderNumber) WHERE OrderNumber Like "%JY8023%" 来确认这一点.有些字符不仅不可见,而且不能用光标选择.但是,它们在那里并且会影响字符串比较.

the string has characters before or after it, that you can't see. try something like select length(OrderNumber) WHERE OrderNumber Like "%JY8023%" to confirm this. Some characters are not only invisible, but unselectable with a cursor. But, they're there and they affect string comparisons.

要遵循的其他调试步骤将是使用子字符串来提取有问题的部分,并使用其他字符串函数来进一步检查该值.像,也许选择字符串作为十六进制编码的字符串将帮助您识别字节.

additional debugging steps to follow will be to use substring to extract the offending part, and other string functions to further inspect the value. like, maybe selecting the string as a hex encoded string will help you identify the bytes.

这篇关于Like 谓词在 SQL 中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆