Solved

How can I grab this in oracle in SQL

Posted on 2015-02-21
6
143 Views
Last Modified: 2015-04-02
Hi,

here is sqlfidlle

http://sqlfiddle.com/#!4/8089b/1

I would like to get the result below out of that...

fist  |  second
100  | 200
101  | 201
102  | 202
103  | 203
104  | 204
105  | 205

regards
0
Comment
Question by:hi4ppl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40623085
What have you tried already, besides 'select * from ....' ?
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40623119
Hi,

I did try select regexp_substr(thatfield,'[^,]+]',2,2) as a table1 but it only pick if it will be the start if it's at end it won't pick it ...
0
 
LVL 32

Expert Comment

by:awking00
ID: 40623177
select
substr(thatfield,instr(thatfield,'{name') + 6,3) as first,
substr(thatfield,instr(thatfield,'{name') + 10,3) as second
from table1;
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 32

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 40623190
With regexp -
select ltrim(regexp_substr(thatfield,',[^,]+',instr(thatfield,'{name')),',') as first,
ltrim(regexp_substr(thatfield,',[^}]+',instr(thatfield,'{name') + 6),',') as second
from table1;
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 250 total points
ID: 40623389
Already some replies above but  I'd first look for that part that contains the numbers:
select regexp_substr (ThatField,'{name,\d{3},\d{3}}') from Table1;

Open in new window


which would result in:
{name,100,200}
{name,101,201}
{name,102,202}
{name,103,203}
{name,104,204}
{name,105,205}

and then 'translate' using regexp_replace it the way you want it:
select
regexp_replace((regexp_substr (ThatField,'{name,\d{3},\d{3}}')),
'({name,)(\d{3}),(\d{3})(})',
'\2|\3')
as "first|second"
from Table1;

Open in new window


(the regexp_replace is finding 4 patterns, I'm only printing 2 and 3 with a | in between)

This results in:

FIRST|SECOND
100|200
101|201
102|202
103|203
104|204
105|205
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40623449
will the "field" widths alter in the data? e.g.

THATFIELD
{blahblah,77100,6200}{secondname,200001}
{muchlongerstringinthislocationwithembeddednumbers123name,17801,201234}
{can spaces exist in this location - question to you,1941,51244}


when preparing sample data make sure it covers all situations (well, at least the most likely)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question