Such a simple request... Yet it hides lots of complexity!
- Will the string always start and end with the parameters?
If so can replace them with null:
select replace (
replace(
'<a>hkjfsdfjashkdfhask_75274_jhsdfbajh</a>', '<a>'
), '</a>'
) val
from dual;
VAL
hkjfsdfjashkdfhask_75274_jhsdfbajh
- If no, you may be able to flex your regular expression muscles:
select regexp_replace(
'asdf<a>hkjfsdfjashkdfhask_75274_jhsdfbajh</a>asdf',
'(.*)(<a>)(.*)(</a>)(.*)', '\3'
) val
from dual;
- But this (probably) only works if the values you're searching for only appear once in the string. Otherwise this regex always gives the last occurrence:
select regexp_replace(
'asdf<a>hkjfsdfjashkdfhask_75274_jhsdfbajh</a>asdf<a>here again</a>',
'(.*)(<a>)(.*)(</a>)(.*)', '\3'
) val
from dual;
VAL
here again
- Is your real requirement to extract values from XML documents based on tags? If so, a little XML processing may be the way to go:
select xmltype('<a>hkjfsdfjashkdfhask_75274_jhsdfbajh</a>').extract('a/text()').getStringVal() val
from dual;
VAL
hkjfsdfjashkdfhask_75274_jhsdfbajh
Sooooooo, what's the full requirement here? What are the edge cases and boundary conditions?