使用SQL语句检测案例
我正在尝试使用 SQL 命令来查看一段文本并确定其中是否包含 3 个连续的大写字母。有办法做到这一点吗?或者更简单的是,SQL 有没有办法检测大小写?
I'm trying to use a SQL command that will look through a block of text and determine if it has 3 consecutive uppercase letters in it. Is there a way of doing this? Or even simpler, is there a way that SQL can detect case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑问题最初被标记为
mysql
,这会起作用。它已被重新标记为sql-server
,这对于 MS SQL Server 无效。您可以使用
REGEXP
在
columnname
匹配的情况下返回 1。EDIT Question was originally tagged
mysql
and this would've worked. It's been re-tagged assql-server
and this isn't valid for MS SQL Server.You could use a
REGEXP
Returns 1 where
columnname
matches.您可以使用的函数 用法
:
结果:
A function you can use
Usage:
Result:
要扩展迈克尔的答案:您可以使用此构造进行区分大小写的比较:
请参阅: http://dev.mysql.com/doc/refman/5.5/en/case-sensitivity.html
和: http://dev.mysql.com /doc/refman/5.0/en/string-comparison-functions.html#operator_like
To expand on Michael's answer: you can do a case sensitive comparison using this construct:
See: http://dev.mysql.com/doc/refman/5.5/en/case-sensitivity.html
and: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like
中大写字母和小写字母比较相等
我已经通过将 varchars 转换为 varbinary 成功比较了大写字母,因为在 SQL SELECT *
从表
WHERE CAST(SUBSTRING(ColumnName,1,3) as varbinary) = CAST(SUBSTRING(UPPER(ColumnName), 1,3) as varbinary)
这样做的一个问题是,如果您有一个像 O'Reilly 这样的名称,它将返回真的。
I've successfully compared uppercase by casting varchars as varbinary, since uppercase and lowercase compare as equal in SQL
SELECT *
FROM Table
WHERE CAST(SUBSTRING(ColumnName,1,3) as varbinary) = CAST(SUBSTRING(UPPER(ColumnName), 1,3) as varbinary)
One problem with this is that if you have a name like O'Reilly, it will return true.