Solved

How can I grab this in oracle in SQL

Posted on 2015-02-21
6
139 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 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
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 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle query help 29 77
Encryption Decryption in Oracle 12 102
alter database link to change the password 2 45
VB.Net - Oracle BulkCopy from CSV Date Format 7 44
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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.  …
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

948 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

21 Experts available now in Live!

Get 1:1 Help Now