ORACLE - 子串

时间:2016-05-07 15:55:42

标签: sql oracle

我在ORACLE-CERTIFICATE发现了一个关于substring(我猜)的问题,我不知道如何做到这一点。有谁理解这个?

创建表Bonus并为以下脚本执行DML插入Bonus表: 提示:您应该能够在没有任何错误的情况下针对您的表运行此脚本并生成输出"结果是"。

select (substr(
          substr(
            substr(
              l.object,
              instr(l.object,',')+1
            ),
            instr(
              substr(
                l.object,
                instr(l.object,',')+1
              ),
              ','
            )+1
          ),
          instr(
            substr(
              substr(l.object,instr(l.object,',')+1),
              instr(
                substr(
                  l.object,
                  instr(l.object,',')+1
                ),
                ','
              )+1
            ),
            ','
          )+1
        )
      ) ref
from  Bonus l
where l.l_index = 't234'

这是输出:

REF                                                         
------------------------------------------------------------
Here is the result

1 个答案:

答案 0 :(得分:0)

是的,它正在寻找第三个逗号后面的字符串的剩余部分:

Oracle安装程序

CREATE TABLE Bonus ( l_index, object ) AS
SELECT 't234', ',,,Here is the result' FROM DUAL;

<强>查询

select (substr(
          substr(
            substr(
              l.object,
              instr(l.object,',')+1
            ),
            instr(
              substr(
                l.object,
                instr(l.object,',')+1
              ),
              ','
            )+1
          ),
          instr(
            substr(
              substr(
                l.object,
                instr(l.object,',')+1
              ),
              instr(
                substr(
                  l.object,
                  instr(l.object,',')+1
                ),
                ','
              )+1
            ),
            ','
          )+1
        )
      ) ref
from  Bonus l
where l.l_index = 't234'

<强>输出

REF                 
---------------------
Here is the result    

此查询的更简单版本为:

SELECT SUBSTR( object, INSTR( object, ',', 1, 3 ) + 1 ) AS ref
FROM   Bonus
WHERE  l_index = 't234';