Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Databases > Re: newbie need...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 290 of 385
Post > Topic >>

Re: newbie needs oracle help

by Lemming <thiswillbounce@[EMAIL PROTECTED] > Jun 15, 2005 at 03:44 PM

On Tue, 14 Jun 2005 23:22:00 -0500, "steve" <a@[EMAIL PROTECTED]
> wrote:

>please refrain from lectures about normalization on this post...i have no

>control over the table schema and am simply trying to normalize data
within 
>this shoddy flat-file type data table.
>
>i've got a table that's basically:
>
>create table foo
>(
>  id       number
>  values   varchar2(32767)
>)
>
>the values column contains space-seperated data like:
>
>A B C D
>
>a row of data in this table would look like:
>
>id       values
>____________________
>
>1        A B C D
>
>i need a query that would return:
>
>id       values
>____________________
>
>1        A
>1        B
>1        C
>1        D
>
>basically, for each id i need to return a row for each value in the
values
>column.

This isn't impossible, you could do it by doing something like
selecting a cartesian product using a self-join, a function to extract
the nth string, then using a statistical function (e.g. MAX) to wrap
everything up together again.  But it would run like a dog.

The basic problem you have is that your data structure is simply
wrong.  If you want the data returned fro a query to be separate, that
implies it should be separate in the first place.  Unlike carpentry
where it's easier to cut things up than it is to stick them together
again, with data it is simpler to add fragments together when required
than to separate them again.

Google "data normalisation" or "data normalization.

Try:

create table foo
(
 id number
,val varchar2(realistic_size)
,primary key (id, val)
);

insert into foo (1, 'A');
insert into foo (1, 'B');
insert into foo (1, 'C');
insert into foo (1, 'D');

select * from foo;

Of course, then your problem might become one of how to stick the data
back together again, but I have a suspicion you don't need to do this.

Lemming
-- 
Curiosity *may* have killed Schrodinger's cat.
 




 4 Posts in Topic:
newbie needs oracle help
"steve" <a@[  2005-06-14 23:22:00 
Re: newbie needs oracle help
Lemming <thiswillbounc  2005-06-15 15:44:44 
Re: newbie needs oracle help
Lemming <thiswillbounc  2005-06-15 15:46:49 
Re: newbie needs oracle help
"steve" <a@[  2005-06-15 10:30:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Aug 28 20:21:06 CDT 2008.