0

I need to extract string from a value of a cell in Oracle table. How can I do that?

VALUE
--------
/var1/var2/var3/C751994ZP1QT11/var4.itp

I want to extract "C751994ZP1QT11" from the value using SQL. I searched some function like REGEXP_LIKE, but I am not quite understand how to use it.

Thanks ahead for the help.

2
  • Thanks all for the answer, :) just made a mistake, there is no ** in between. Please see correction above. Commented Aug 29, 2012 at 5:33
  • So what is the criteria? Do you want the 3rd folder name? Do you want the last folder name before the file name? The existing answers show how to extract strings, so you should be able to figure it out. But if you can't, no one can show you how unless you are more specific as to your requirements. Commented Aug 29, 2012 at 12:12

2 Answers 2

1

If you want to extract a string, you need to use regexp_substr(). regexp_like() would return a boolean indicating if a certain regular expression matches your string, while regexp_substr() actually returns the matched string.

In your case, assuming you want the string between /** and **/, you could use something like this:

select 
  regexp_substr(
    '/var1/var2/var3/**C751994ZP1QT11**/var4.itp', 
    '/\*\*.*\*\*/') 
from dual

Refer here for some useful shortcuts on regular expressions with Oracle.

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

Comments

0
select REGEXP_REPLACE('/var1/var2/var3/**C751994ZP1QT11**/var4.itp','.*\*\*(.*)\*\*.*','\1') result from dual

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.