Solved

ORACLE - split string and populate Q

Posted on 2007-03-23
6
3,106 Views
Last Modified: 2013-12-19
ORACLE 10G

I have a table with a string in the format for example.......      '00001000090003D

I have a view that has been created from that table to show split the string up like this

col2    col2      col3 col4
00001 00009  003  D

How would I incorporate into my view to get it so that I can populate a 5th col (col5) with the contents from col2, col3, col4 and have the data separated by a . or -

thanks

Jimbo
0
Comment
Question by:jim_bob_jim
6 Comments
 
LVL 7

Expert Comment

by:Docteur_Z
Comment Utility
select col1||'-'||col2||'-'||col3||'-'||col4 "col5" from yourtable
in your view

or if you want it "inline" :
update yourtable set col5=col1||'-'||col2||'-'||col3||'-'||col4
if each field is caracters.
0
 

Author Comment

by:jim_bob_jim
Comment Utility
within my table col1 is '00001000090003D'

my view has that column split up into 4 different columns using the SUBSTR command

I need to be able to within my view select a 5th coloumn and have in that column the data from col1, col3, col4 all separated by a '.' or '-' Im not interested with col2

I had already tried your method but I think it is failing cause it needs to select from the columns within the view

any thoughts
0
 
LVL 2

Accepted Solution

by:
Tayger earned 500 total points
Comment Utility
Should work that way (dont know the exact substr-pos):

Create or replace view xyz
select subsr(0,4) col1,
           substr (4,8) col2,
           substr (8,12) col3,
           substr (12,16) col4,
           subsr(0,4) ||'-'|| substr (8,12)  ||'-'|| substr (12,16)          -- col5 (= col1, col3, col4)
from orig_table

you need to reselect the data from the orig table for the column you want it.
Greetings
Tayger



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 2

Expert Comment

by:Tayger
Comment Utility
sorry, mistake in substr ('whole_string'),pos, length)....

Docteur Z's way should work as well, easier way... You can concatenate several columns of the same record and displaying it next to single column values.
Tayger
0
 
LVL 6

Expert Comment

by:morphman
Comment Utility
Alternatively, create a view-on-a-aview

create view myview2 as
select a.*, col1 || '.' || col3 || '.' || col4 as col5 from myview;
0
 
LVL 2

Expert Comment

by:Tayger
Comment Utility
Hello again

IMHO, just putting a view on a view is not really recommandable for shwoing a additional column.
If the showed possible are not the solution you are looking for you maybe put a view display example how you would like to have it(?).
Tayger
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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

728 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

11 Experts available now in Live!

Get 1:1 Help Now