Solved

ORACLE - split string and populate Q

Posted on 2007-03-23
6
3,114 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
[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 7

Expert Comment

by:Docteur_Z
ID: 18781262
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
ID: 18781442
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
ID: 18783991
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 2

Expert Comment

by:Tayger
ID: 18784003
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
ID: 18784753
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
ID: 18784898
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

634 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