Hi there I'm trying to extract from an oracle database part of the text contained within a single field using the REGEXP_SUBSTR function. The text in question is shown in bold text below "BRS14774366". The good news is the pattern of the data i'm trying to extract is fairly consistent in that it always begins with "-" and ends with "CSN", however the text between which I'm trying to consistently extract is not always the same and can consist of both alpha and numeric characters and be between 1-12 characters in length.
PSN932-52506252-BRS14774366CSN/SF-1/25JAN0524
Below are further examples showing the slight differences in length, again the text i'm trying to extract is shown in bold. As you can see the position is always the same but the Alpha numeric characters can be anywhere between "-" and "CSN" with differing lengths.
PSN932-49837056-DELAIR09364CSN/SF-66/25JAN0541
PSN932-51231434-H1001865CSN/SF-5/25JAN0546
PSN932-52648256-2EGA814CSN/SF-10/25JAN0549
Taking the first sample data (PSN932-52506252-BRS14774366CSN/SF-1/25JAN0524) I created the below query that outputs the data correctly, however this query doesn't consider that the text can consist of both Alpha/numeric characters with a varying length between 1-12 characters
SELECT REGEXP_SUBSTR('PSN932-52506252-BRS14774366CSN/SF-1/25JAN0524', '-(\D\D\D\d\d\d\d\d\d\d\d)',1 ,1, 'i',1) "REGEXP_SUBSTR" FROM DUAL;
output of above query is as follows:
BRS14774366
Can anyone tell me how to format the match pattern in the query so I can consistently extract the data between "-" and "CSN"?
As always appreciate any assistance people can provide?
Update - it seems the data is stored containing carriage returns so the below query doesn't work:
SELECT
REGEXP_SUBSTR('PSN
932-52506252-BRS14774366
CSN/SF-1/25JAN0524', '-(\w+)CSN', 1, 1, 'i', 1) "REGEXP_SUBSTR"
FROM DUAL;
works fine if the data was like this:
SELECT
REGEXP_SUBSTR('PSN932-52506252-BRS14774366CSN/SF-1/25JAN0524', '-(\w+)CSN', 1, 1, 'i', 1) "REGEXP_SUBSTR" FROM DUAL;
Can this function deal with carriage returns?