我们可以使用“NOT LIKE”吗?在 SQL 中

发布于 2025-01-06 03:46:25 字数 371 浏览 2 评论 0原文

我们可以使用与 LIKE '%abc%' 相反的 "NOT LIKE '%abc%'" 吗? 我尝试并得到了一些结果,但看起来不正确!

有没有类似于 SQL 中的正则表达式的东西。

例如:

我有一个包含 3 个字段的表。

id  name  address
1    xyz    1234 abcd 
2    abc    nomans land
3    omg    #123 new-york
3    nom    $123 &7up

我可以获取带有特殊字符的地址**,而不需要一一检查每个特殊字符吗?如何

Can we use "NOT LIKE '%abc%'" just opposite of LIKE '%abc%' ?
i tried and got some result but dont look like correct!!

Is there anything similar to regex in SQL.

Eg:

i hae a table with 3 field.

id  name  address
1    xyz    1234 abcd 
2    abc    nomans land
3    omg    #123 new-york
3    nom    $123 &7up

can i fetch the address **with special characters with out checking each special character one by one . How

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

分开我的手 2025-01-13 03:46:25

在 SQL Server 中。如果您想要包含字母数字和空格以外的字符的地址:

address LIKE '%[^0-9a-zA-Z ]%';

注意 ^ 字符意味着“不在指定范围内的任何单个字符”。不确定 DB2 中是否可能出现非常类似的情况。

In SQL Server. if you wanted addresses that contained characters other than alphanumerics and spaces:

address LIKE '%[^0-9a-zA-Z ]%';

noting the ^ character means "any single character not within the specified range". Not sure if something very similar is possible in DB2.

尘曦 2025-01-13 03:46:25

当然,请查看此处。还支持 NOT LIKE。

Sure, look here. Also NOT LIKE is supported.

淡笑忘祈一世凡恋 2025-01-13 03:46:25

在 db2(版本 9.7.900.250)中,我已成功指定“不喜欢”:

select * from orders
where not(orders.order_number like 'S%')

这显示了 order# 不以大写“S”开头的所有订单。

In db2 (version 9.7.900.250), I've successfully specified "not like" this way:

select * from orders
where not(orders.order_number like 'S%')

This shows all orders where the order# does NOT start with a capital "S".

女中豪杰 2025-01-13 03:46:25

没有给出“尝试并得到一些结果但看起来不正确!!”的描述。关于主题查询,但在审查给定数据和OP中的两个谓词时,请考虑以下内容;请注意,辅助正则表达式查询显然已经得到答复和接受,因此在此响应中被忽略:

with
  xmp (id, name, address) as
( values ( 1  ,  'xyz'  ,  '1234 abcd '    )
       , ( 2  ,  'abc'  ,  'nomans land'   )
       , ( 3  ,  'omg'  ,  '#123 new-york' )
       , ( 3  ,  'nom'  ,  '$123 &7up'     )
)
select id
from xmp
where address NOT LIKE '%abc%'

上述 DB2 查询应产生集合 {(2), (3), (3)};即包括除第一行之外的所有行。将谓词从 address NOT LIKE '%abc%' 更改为 address LIKE '%abc%' 应产生集合 {(1)};即仅包括第一行。以 address NOT LIKE '%abc%'NOT (address LIKE '%abc%') 形式指定谓词应产生相同的结果;它们在逻辑上是相同的请求。

No description was given for what was "tried and got some result but don't look like correct!!" with regard to the Subject inquiry, but in review of the given data and the two predicates from the OP, consider the following; noting, the secondary regex inquiry is apparently already answered and accepted, so is ignored in this response:

with
  xmp (id, name, address) as
( values ( 1  ,  'xyz'  ,  '1234 abcd '    )
       , ( 2  ,  'abc'  ,  'nomans land'   )
       , ( 3  ,  'omg'  ,  '#123 new-york' )
       , ( 3  ,  'nom'  ,  '$123 &7up'     )
)
select id
from xmp
where address NOT LIKE '%abc%'

The above DB2 query should yield the set {(2), (3), (3)}; i.e. include all but the first row. Changing the predicate from address NOT LIKE '%abc%' to address LIKE '%abc%' should yield the set {(1)}; i.e. include only the first row. The specification of the predicate in either form address NOT LIKE '%abc%' or NOT (address LIKE '%abc%') should yield the same result; they are logically identical requests.

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