替换两个字符中断之间的信息

时间:2015-11-12 06:29:51

标签: sql oracle

我想替换两个字符中断之间的信息“|”

中的数据
Parameters_Sent_To_Procdure|Information_to_replace_|Put_the_existing_information_back

所以我想把现有参数重新替换为两个 Pipes“|”之间的信息,然后将信息放回第二个管道之后

1 个答案:

答案 0 :(得分:2)

  

我想替换两个字符中断之间的信息" |"

最简单的方法是提取子字符串,连接它与您想要替换期望值 >使用以下然后连接所有内容

  • SUBSTR
  • INSTR

SQL> WITH DATA AS
  2    (SELECT 'Parameters_Sent_To_Procdure|Information_to_replace_|Put_the_existing_information_back' str
  3    FROM dual
  4    )
  5  SELECT SUBSTR(str, 1, instr(str, '|', 1,1) -1)
  6    || ''
  7    || SUBSTR(str, instr(str, '|', 1, 1) + 1,
  8                   instr(str, '|', 1, 2) -
  9                  instr(str, '|', 1, 1) -1) AS "new_str"
 10  FROM data;

new_str
--------------------------------------------------------------------------------------------
Parameters_Sent_To_ProcdureInformation_to_replace_

查询的工作原理:

SELECT SUBSTR(str, 1, instr(str, '|', 1,1) -1)

上述SUBSTR提取字符串的第一部分,即从字符串的开头|第一次出现

'<Here goes the string you want to replace>'

以上应该是你的新价值。

SUBSTR(str, instr(str, '|', 1, 1) + 1, 
            instr(str, '|', 1, 2) - 
            instr(str, '|', 1, 1) -1)

上面的SUBSTR提取字符串的最后一部分,即从|第二次出现到字符串的结尾