我想知道字符串的最后一个字符是否是星号 *
我有以下内容给了我最后一个字符:
select RIGHT('hello*',1)
Run Code Online (Sandbox Code Playgroud)
但是如何通过匹配将它作为if语句中的条件使用呢?以下不起作用,因为它只返回最后一个char.
select '*' = RIGHT('hello*',1)
Run Code Online (Sandbox Code Playgroud)
我可以使用正则表达式吗?
你就在那里.通过使用:
select '*' = RIGHT('hello*',1)
Run Code Online (Sandbox Code Playgroud)
Sql评估RIGHT但是认为你想将它别名为一个名为的列*
您可以有条件地使用表达式:
if RIGHT('hello*',1) = '*'
print 'Ends in *'
else
print 'Does not end in *'
Run Code Online (Sandbox Code Playgroud)
您可以在表格上进行过滤:
select *
from MyTable
where RIGHT(MyColumn, 1) = '*';
Run Code Online (Sandbox Code Playgroud)
虽然表现不会很出色.编辑:请参阅Karl Kieninger关于如何大大提高此查询性能的想法的答案
| 归档时间: |
|
| 查看次数: |
6567 次 |
| 最近记录: |