OP_Zaharin
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...
- 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Quite a few ways to do this. One, probably not the most efficient:
LEFT(SUBSTR(column1,INSTR( column1,'_ '),LEN(col umn1)),INS TR(SUBSTR( column1,IN STR(column 1,'_'),'_' )
LEFT(SUBSTR(column1,INSTR(
ASKER
- angelll suggestion works perfect, thank you!. i've also try the other two however return error.
OP
OP
SUBSTR(columnname ,instr(columnname , '_') , instr(columnname, '_', 1, 2))