Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a substring from a column with another string as a reference

Status
Not open for further replies.

chris01010

Programmer
Jan 29, 2004
25
GB
Hi,

I'm trying to select a substring within a column but using another string as the starting point. This is because the position of the string in the column may change.

i.e.

Code:
select substr(<column name>,<reference string>,3) from table;

ABCDEFGHIJKLMNOPMSGNO123ABCDEFGHIJKL

The refence string in the above is MSGNO so the query would return 123.

Question 1: Is this even possible?

Question 2: How do you do it? :0)

Thanks

Chris
 
SELECT
substr('ABCDEFGHIJKLMNOPMSGNO123ABCDEFGHIJKL',
(instr('ABCDEFGHIJKLMNOPMSGNO123ABCDEFGHIJKL','MSGNO')+5),3) as x,
REGEXP_SUBSTR('ABCDEFGHIJKLMNOPMSGNO123ABCDEFGHIJKL', '[0-9]+') as z
FROM dual

Another way is to use regular expressions which is a good way to find patterns in a string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top