【问题标题】:Using SUBSTR() AND INSTR() find end of string使用 SUBSTR() AND INSTR() 查找字符串的结尾
【发布时间】:2015-08-29 11:18:57
【问题描述】:

我有一个问题,从一个字符串中选择一个子字符串。相等后的字符串。我的示例看起来像这样。

string='test = 1234sg654'

我的想法是选择等于“1234sg654”之后的字符串,这样:用 Instr() 找到相等的位置,然后用 Substr(),减去相等后的字符串,直到字符串结束。

equal=INSTR(string,'=',1,1);
aux=Substr(string,-1,equal); // -1 I thought that is represent end of line

但结果不是 1234sg654 我的错在哪里?

【问题讨论】:

    标签: sql plsql oracle11g plsqldeveloper


    【解决方案1】:

    不要将-1 用于position 参数——子字符串从字符串末尾开始那么多字符。你可以这样做:

    aux = substr(string, instr(string, '=') + 1)
    

    没有第三个​​参数的意思是“到字符串的末尾”。

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 1970-01-01
      • 2016-04-16
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      相关资源
      最近更新 更多