问题
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;
回答1:
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
回答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>
来源:https://stackoverflow.com/questions/49027346/oracle-regexp-substr-fetch-string-between-two-delimiters