0

I have a string Organization, INC..Truck/Equipment Failure |C. I want to fetch the sub-string after organization name (after two '..' characters) and before pipe character. So the output string should be - Truck/Equipment Failure. Can you please help.

I have been trying forming regexp like this but doesn't seem working.

select regexp_substr('Organization, INC..Truck/Equipment Failure |C', '[^.]+',1,2) from dual;

2 Answers 2

6

You may use this.

SELECT REGEXP_SUBSTR ('Organization, INC..Truck/Equipment Failure |C',
                      '([^.]+)\|',
                      1,
                      1,
                      NULL,
                      1)
  FROM DUAL;

EDIT: This will match exactly two dots followed by one or more characters other than a | till the end of string.

SELECT REGEXP_SUBSTR ('Organization, INC..Truck/Equipment Failure',
                      '\.{2}([^|]+)',
                      1,
                      1,
                      NULL,
                      1)
  FROM DUAL;

DEMO

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Kaushik for quick response. This works but there is one problem. If the input string is Organization, INC..Truck/Equipment Failure, that is, if it is without pipe substring, it returns NULL. In that case it should return Truck/Equipment Failure. Can you please help with this.
@AmitJagtap : So it means in some cases you don't have pipe. What should we rely on then? end of string ? Are these two the only cases or do you have any other format?
There are only two cases: Organization, INC..Truck/Equipment Failure |C and Organization, INC..Truck/Equipment Failure.
@AmitJagtap : You are welcome. It is always better to include all cases to expect while asking the question to avoid confusion.
hi is there any way to this in oracl 10g
2

Classic SUBSTR + INSTR option:

SQL> with test as (select 'Organization, INC..Truck/Equipment Failure |C' col from dual)
  2  select substr(col, instr(col, '..') + 2,
  3                     instr(col, '|') - instr(col, '..') - 2
  4                ) result
  5  from test;

RESULT
------------------------
Truck/Equipment Failure

SQL>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.