如何从字符上获取子字符串

问题描述

我有一个带有varchar2列的表,其中有不同长度的字符串,我必须提取字符'-'之后的子字符串。

GET https://outlook.office365.com/api/v2.0/me/

我想在'-'字符之后得到所有内容

你能告诉我怎么做吗? 甲骨文10g

提前谢谢! 标记

解决方法

看起来像旧的SUBSTR + INSTR组合。如果要删除前导/后缀空格,请应用TRIM

SQL> select string_col,2    substr(string_col,instr(string_col,'-') + 1) result,3    --
  4    trim(substr(string_col,'-') + 1)) trimmed_result
  5  from test;

STRING_COL                                         RESULT               TRIMMED_RESULT
-------------------------------------------------- -------------------- --------------------
afg a ga ga ga ggfdg - gfd g f                      gfd g f             gfd g f
ok k ok o - gfs gsd gsg sd g sd                     gfs gsd gsg sd g sd gfs gsd gsg sd g sd
okk - jdjdjdj d d                                   jdjdjdj d d         jdjdjdj d d

SQL>
,

您可以使用regexp_substr()

select regexp_substr(string_col,'[^-]+$')

Here是db 小提琴。