是“charlist”吗?样式通配符是 SQL-92 标准的一部分吗?
SQL 通配符“%”和“_”已有详细记录并广为人知。然而,正如 w3schools 所解释的,还有“charlist”样式的通配符用于匹配其中的单个字符或在给定范围之外,例如要查找所有名为 Carl 的人,但不查找名为 Earl 的人:
select * from Person where FirstName like '[A-D]arl'
... 或查找相反的人,请使用:
select * from Person where FirstName like '[!A-D]arl'
或 (大概取决于 RDBMS):
select * from Person where FirstName like '[^A-D]arl'
这种类型的通配符是SQL-92 标准,哪些数据库真正支持它?例如:
- Oracle 11g 不支持
- SQL Server 2005 支持,否定运算符为“^”(不是“!”)
The SQL wildcards "%" and "_" are well documented and widely known. However as w3schools explains, there are also "charlist" style wildcards for matching a single character within or outside a given range, for example to find all the people called Carl but not those called Earl:
select * from Person where FirstName like '[A-D]arl'
... or to find the opposite, use either:
select * from Person where FirstName like '[!A-D]arl'
or (depending on the RDBMS, presumably):
select * from Person where FirstName like '[^A-D]arl'
Is this type of wildcard part of the SQL-92 standard, and what databases actually support it? For example:
- Oracle 11g doesn't support it
- SQL Server 2005 supports it, with the negation operator being "^" (not "!")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQL-99 标准有一个
SIMILAR TO
谓词,它使用“charlist”样式以及“%”和“_”通配符。不过,SQL-92 标准中没有类似的内容(没有双关语)。
The SQL-99 Standard has a
SIMILAR TO
predicate which uses "charlist" style as well as the "%" and "_" wildcard characters.Nothing similar (no pun intended) in the SQL-92 Standard, though.
“charlist”运算符看起来像正则表达式,或者它们的有限子集。 AFAIK SQL-92 中没有指定正则表达式语法,尽管许多数据库支持正则表达式,并且它们支持的方式各不相同。例如,Oracle 具有进行正则表达式比较和替换的函数。不知道别人是怎么做到的。
分享并享受。
The "charlist" operators look like regular expressions, or a limited subset of them. AFAIK there's no regular expression syntax specified in SQL-92 although many databases support regex's, and HOW they support it varies. Oracle, for example, has functions to do regular expression comparisons and substitutions. Don't know how others do it.
Share and enjoy.