извлечь подстроку из строки в оракуле - PullRequest
0 голосов
/ 01 марта 2019

У меня есть одна из следующих строк:

(,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 голосов
/ 01 марта 2019

Используйте регулярное выражение для замены всего, начиная с каждого символа ~ тильды и заканчивая следующей запятой , или символом | канала (исключая этот последний символ):

Oracle Setup :

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

дБ<> скрипка здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...