带有 LIKE 的 SQL 语句
我想选择第 11 个字符中有下划线字符的所有记录, 所以我尝试这个:
SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '%%%%%%%%%%_%%%'
但这并没有按预期工作,有人可以帮忙吗?
I would like to select all records that have an underscore character in their 11th character,
so i try this:
SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '%%%%%%%%%%_%%%'
but this doesnt work as expected, can someone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只需使用“SUBSTRING”功能即可:
Marc
Just use the "SUBSTRING" function :
Marc
对于单个字符通配符,请使用
_
。 对于多个字符通配符,请使用%
。 要转义_
的“真实”外观,请使用\_
(感谢 Bill!)。尝试以下代码:
为了进一步详细说明 Dav 的注释,请注意 '%%%' 与 '%' 完全相同,因为根据定义 '%' 涵盖多个字符。
For a single character wildcard use
_
. For multiple characters wildcards, use%
. To escape a "real" appearance of_
, use\_
(thanks Bill!).Try the following code:
To further elaborate following Dav's comment, note that '%%%' is exactly the same as '%', since by definition '%' covers multiple characters.
pervasive 使用 _ 来匹配任何单个字符,使用 \_ 来实际匹配下划线。
所以选择将是:
pervasive uses _ to match any single character and \_ to actually match an underscore.
so the select would be:
LIKE % 可以表示任意数量的字符,使用 LIKE _ 表示仅一个字符。 由于您正在寻找下划线,因此需要使用 ! 对其进行转义。
LIKE % can mean any number of characters, use LIKE _ to mean just one. Since you're looking for an underscore, you need to escape it with !.
% 不是每个字符的通配符,它是字符串通配符的开头和结尾。
即,如果我想查找其中包含“car”的所有行,我会这样做:
Select * from myTable where myCol LIKE '%car%'
如果我只想查找以 car 开头的行:
Select * from myTable where myCol LIKE 'car%'
并以 car 结尾:
Select * from myTable where myCol LIKE '%car'
The % is not a per character wildcard, its a beginning and end of string wild card.
i.e. if I want to find all rows that have "car" in them, I would do this:
Select * from myTable where myCol LIKE '%car%'
If I wanted just the rows that STARTED with car:
Select * from myTable where myCol LIKE 'car%'
and ended with car:
Select * from myTable where myCol LIKE '%car'
% 是通配符,可以替换一个字符或字符组合。 使用 ? 相反,它替换单个字符。
% is a wildcard and can replace an character, or combination of characters. Use ? instead which replaces a single character.
你可以尝试这样的事情:(玩数字,我没有普遍的测试)
You can try something like: (play with the numbers, I don't have pervasive to test with)