0

Hi I am trying to fetch substring in oracle for the below two strings. I want result if the pattern matches starting with S9C and the having next numbers

For Eg: for the below two inputs I need output like

Input:

 1.CABLE : THERMINAL 3X2X0.25MM FPCP PLUS UNITRONIC S9C000019651  
 2.Motor Protection Relay EMR-3MPO-2S9CB1-1 (was IQ1000II / MP 3000)
 3.GREASE : BEM 41-132 3KG CARTRIDGE KLUBERPLEX S9C00019171 (Order by KG's required)
 4.DO NOT USE CARRIER SPIDEX ZK 38 98 SH. S9C00011593 (SUPERSEDE BY S9C10204555 - WIN0020775)

Output:

1.S9C000019651
2.Null
3.S9C00019171
4.S9C10204555

Or Else the Better way is to fetch first matching String from back of the text.

0

1 Answer 1

1

I think you can achieve the desired result with below script where you can pick the second group. If that is null, Pick the first group -

WITH DATA AS (SELECT 'CABLE : THERMINAL 3X2X0.25MM FPCP PLUS UNITRONIC S9C000019651' STR FROM DUAL
              UNION ALL
              SELECT 'Motor Protection Relay EMR-3MPO-2S9CB1-1 (was IQ1000II / MP 3000)' FROM DUAL
              UNION ALL
              SELECT 'GREASE : BEM 41-132 3KG CARTRIDGE KLUBERPLEX S9C00019171 (Order by KG''s required)' FROM DUAL
              UNION ALL
              SELECT 'DO NOT USE CARRIER SPIDEX ZK 38 98 SH. S9C00011593 (SUPERSEDE BY S9C10204555 - WIN0020775)' FROM DUAL)
SELECT NVL(REGEXP_SUBSTR(STR, 'S9C\d{7,}', 1, 2), REGEXP_SUBSTR(STR, 'S9C\d{7,}'))
  FROM DATA;

Demo.

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

6 Comments

what if i need matching with only 8 digits after A9B else Null
Only 8 digits or at least 8 digits?
Only 8 digits after 8
THen you can try REGEXP_SUBSTR(STR, 'S9C\d{8,8}')
No its not working. its elimination records having digits less than 8
|

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.