Link to home
Start Free TrialLog in
Avatar of OP_Zaharin
OP_ZaharinFlag for Malaysia

asked on

sql query to get value from a string

hi fellow experts,
- i am working on a data conversion task and after 24hours of non-sleep, i'm unable to get my brain working on this. i have list of data as below in an Oracle table, and i need to extract the value in middle, in-between the two underscore '_'. the length can be vary:  

column1
======================
asbc134_123acd_2345-10
a655s_bgddg_as45-05
s5gg6a_bhb89hj_2f677-15
dds4rr4_19898sd_265ff-01


- expected result:
column1
======================
123acd
bgddg
bhb89hj
19898sd

- any method is welcome either using regular expression or substr-instr...
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
check with this
SUBSTR(columnname ,instr(columnname , '_')  , instr(columnname, '_', 1, 2))
Quite a few ways to do this. One, probably not the most efficient:
LEFT(SUBSTR(column1,INSTR(column1,'_'),LEN(column1)),INSTR(SUBSTR(column1,INSTR(column1,'_'),'_')
Avatar of OP_Zaharin

ASKER

- angelll suggestion works perfect, thank you!. i've also try the other two however return error.

OP