oracle 12c-在最后一次出现字符后选择字符串 [英] oracle 12c - select string after last occurrence of a character

查看:294
本文介绍了oracle 12c-在最后一次出现字符后选择字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串:

ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence

所以我想选择Sentence,因为它是最后一个句点之后的字符串.我该怎么办?

So I want to select Sentence since it is the string after the last period. How can I do this?

推荐答案

您可能可以使用复杂的正则表达式执行此操作.我喜欢以下方法:

You can probably do this with complicated regular expressions. I like the following method:

select substr(str, - instr(reverse(str), '.') + 1)

没有什么比测试更清楚的说明了当字符串在末尾时,这是行不通的.大约-0 =0.这是一个改进:

Nothing like testing to see that this doesn't work when the string is at the end. Something about - 0 = 0. Here is an improvement:

select (case when str like '%.' then ''
             else substr(str, - instr(reverse(str), ';') + 1)
        end)

您的示例在我在本地Oracle上和 SQL Fiddle 中运行时都有效.

Your example works, both when I run it on my local Oracle and in SQL Fiddle.

我正在运行以下代码:

select (case when str like '%.' then ''
             else substr(str, - instr(reverse(str), '.') + 1)
        end)
from (select 'ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence' as str from dual) t

这篇关于oracle 12c-在最后一次出现字符后选择字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆