我们可以使用“NOT LIKE”吗?在 SQL 中
我们可以使用与 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 SQL Server 中。如果您想要包含字母数字和空格以外的字符的地址:
注意
^
字符意味着“不在指定范围内的任何单个字符”。不确定 DB2 中是否可能出现非常类似的情况。In SQL Server. if you wanted addresses that contained characters other than alphanumerics and spaces:
noting the
^
character means "any single character not within the specified range". Not sure if something very similar is possible in DB2.当然,请查看此处。还支持 NOT LIKE。
Sure, look here. Also NOT LIKE is supported.
在 db2(版本 9.7.900.250)中,我已成功指定“不喜欢”:
这显示了 order# 不以大写“S”开头的所有订单。
In db2 (version 9.7.900.250), I've successfully specified "not like" this way:
This shows all orders where the order# does NOT start with a capital "S".
没有给出“尝试并得到一些结果但看起来不正确!!”的描述。关于主题查询,但在审查给定数据和OP中的两个谓词时,请考虑以下内容;请注意,辅助正则表达式查询显然已经得到答复和接受,因此在此响应中被忽略:
上述 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:
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%'
toaddress LIKE '%abc%'
should yield the set {(1)}; i.e. include only the first row. The specification of the predicate in either formaddress NOT LIKE '%abc%'
orNOT (address LIKE '%abc%')
should yield the same result; they are logically identical requests.