从oracle中的字符串中提取子字符串

时间:2019-03-01 09:35:42

标签: sql oracle

我有以下字符串之一:

(,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,)

我应该怎么做?

1 个答案:

答案 0 :(得分:0)

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

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

输出

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

db <>提琴here

相关问题