• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

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...
0
OP_Zaharin
Asked:
OP_Zaharin
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
instr has the 4th parameter of nth occurance, which should make something like this:
http://www.techonthenet.com/oracle/functions/instr.php
substr( column1, instr( column1, '_' ) + 1, instr( column1, '_', 1, 2) - instr( column1, '_' ) - 1 )

Open in new window

0
 
santhimurthydCommented:
check with this
SUBSTR(columnname ,instr(columnname , '_')  , instr(columnname, '_', 1, 2))
0
 
CluskittCommented:
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,'_'),'_')
0
 
OP_ZaharinAuthor Commented:
- angelll suggestion works perfect, thank you!. i've also try the other two however return error.

OP
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now