Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

How can I grab this in oracle in SQL

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
hi4ppl
Asked:
hi4ppl
2 Solutions
 
Gerwin Jansen, EE MVETopic Advisor Commented:
What have you tried already, besides 'select * from ....' ?
0
 
hi4pplAuthor Commented:
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
 
awking00Commented:
select
substr(thatfield,instr(thatfield,'{name') + 6,3) as first,
substr(thatfield,instr(thatfield,'{name') + 10,3) as second
from table1;
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
awking00Commented:
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
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
PortletPaulCommented:
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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

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