oracle 12c - select string after last occurrence of a character

前端 未结 5 1779
旧时难觅i
旧时难觅i 2020-12-11 02:27

I have below string:

ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence

So I want to select Sentence since it is the string a

5条回答
  •  佛祖请我去吃肉
    2020-12-11 03:15

    And yet another way.

    Not sure from a performance standpoint which would be best...

    The difference here is that we use -1 to count backwards to find the last . when doing the instr.

      With CTE as 
      (Select 'ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence' str, length('ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence') len from dual)
      Select substr(str,instr(str,'.',-1)+1,len-instr(str,'.',-1)+1) from cte;
    

提交回复
热议问题