Solved

How can I grab this in oracle in SQL

Posted on 2015-02-21
6
138 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
6 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen
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 31

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 31

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 37

Accepted Solution

by:
Gerwin Jansen 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
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.  …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now