带有 LIKE 的 SQL 语句

发布于 2024-08-02 00:40:36 字数 165 浏览 7 评论 0原文

我想选择第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

回梦 2024-08-09 00:40:36

只需使用“SUBSTRING”功能即可:

SELECT * FROM "BOM_SUB_LEVEL" where SUBSTRING(TOP_CODE, 11, 1) = "_"

Marc

Just use the "SUBSTRING" function :

SELECT * FROM "BOM_SUB_LEVEL" where SUBSTRING(TOP_CODE, 11, 1) = "_"

Marc

漫雪独思 2024-08-09 00:40:36

对于单个字符通配符,请使用 _。 对于多个字符通配符,请使用 %。 要转义 _ 的“真实”外观,请使用 \_ (感谢 Bill!)。

尝试以下代码:

SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '___________\_%'

为了进一步详细说明 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:

SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '___________\_%'

To further elaborate following Dav's comment, note that '%%%' is exactly the same as '%', since by definition '%' covers multiple characters.

绻影浮沉 2024-08-09 00:40:36

pervasive 使用 _ 来匹配任何单个字符,使用 \_ 来实际匹配下划线。

所以选择将是:

SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '___________\_%' 

pervasive uses _ to match any single character and \_ to actually match an underscore.

so the select would be:

SELECT * FROM "BOM_SUB_LEVEL" where TOP_CODE like '___________\_%' 
夏の忆 2024-08-09 00:40:36

LIKE % 可以表示任意数量的字符,使用 LIKE _ 表示仅一个字符。 由于您正在寻找下划线,因此需要使用 ! 对其进行转义。

SELECT * FROM BOM_SUB_LEVEL WHERE TOP_CODE 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 !.

SELECT * FROM BOM_SUB_LEVEL WHERE TOP_CODE LIKE '__________!_%'
红墙和绿瓦 2024-08-09 00:40:36

% 不是每个字符的通配符,它​​是字符串通配符的开头和结尾。

即,如果我想查找其中包含“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'

第七度阳光i 2024-08-09 00:40:36

% 是通配符,可以替换一个字符或字符组合。 使用 ? 相反,它替换单个字符。

% is a wildcard and can replace an character, or combination of characters. Use ? instead which replaces a single character.

待"谢繁草 2024-08-09 00:40:36

你可以尝试这样的事情:(玩数字,我没有普遍的测试)

SELECT * 
  FROM BOM_SUB_LEVEL 
 where SUBSTRING(TOP_CODE, 11,1) = '-'

You can try something like: (play with the numbers, I don't have pervasive to test with)

SELECT * 
  FROM BOM_SUB_LEVEL 
 where SUBSTRING(TOP_CODE, 11,1) = '-'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文