【问题标题】:extract sub string from string in oracle从oracle中的字符串中提取子字符串
【发布时间】:2019-07-23 07:36:24
【问题描述】:

我有以下字符串之一:

(,QUESTION-3914~Please enter the unique identification number associated with the IRQ.|3~Greater Than|5~5,AND,QUESTION-3920~Select the contract action that applies to this IRQ.|5~Equal To|LOV1274~New Agreement,),AND,QUESTION-3921~If "New Agreement@comma@" which type of New Agreement is being requested?|5~Equal To|y~Yes,OR,NOT,(,QUESTION-3923~Will the Third Party Relationship support the implementation@comma@ pilot@comma@ launch@comma@ or operation of a New Activity (as defined in the New Activity Risk Management Policy)?|5~Equal To|y~Yes,)

我想要这个字符串所需的输出是这样的:-

(,QUESTION-3914|3|5,AND,QUESTION-3920|5|LOV1274,),AND,QUESTION-3921|5|y,OR,NOT,(,QUESTION-3923)|5|y,)

我该怎么办?

【问题讨论】:

  • 从 A 到 B 的规则是什么?
  • 您应该过滤字符串,使其不包含您不包含的部分。
  • @AlexanderDmitriev:我不明白你。

标签: sql oracle


【解决方案1】:

使用正则表达式替换从每个~ 波浪字符到下一个逗号, 或管道| 字符(不包括最后一个字符)的所有内容:

Oracle 设置

CREATE TABLE your_data ( input_string ) AS
SELECT '(,QUESTION-3914~Please enter the unique identification number associated with the IRQ.|3~Greater Than|5~5,AND,QUESTION-3920~Select the contract action that applies to this IRQ.|5~Equal To|LOV1274~New Agreement,),AND,QUESTION-3921~If "New Agreement@comma@" which type of New Agreement is being requested?|5~Equal To|y~Yes,OR,NOT,(,QUESTION-3923~Will the Third Party Relationship support the implementation@comma@ pilot@comma@ launch@comma@ or operation of a New Activity (as defined in the New Activity Risk Management Policy)?|5~Equal To|y~Yes,)' FROM DUAL

查询

SELECT REGEXP_REPLACE( input_string, '~.*?([|,])', '\1' ) AS output
FROM   your_data d

输出

|输出 | | :------------------------------------------------ -------------------------------------------------- | | (,QUESTION-3914|3|5,AND,QUESTION-3920|5|LOV1274,),AND,QUESTION-3921|5|y,OR,NOT,(,QUESTION-3923|5|y,) |

db小提琴here

【讨论】:

    猜你喜欢
    • 2021-01-29
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 1970-01-01
    • 2012-04-25
    • 2019-12-11
    相关资源
    最近更新 更多