Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Separate word in a field

Re: Separate word in a field

From: Robert Klemme <shortcutter_at_googlemail.com>
Date: Fri, 08 Dec 2006 09:20:49 +0100
Message-ID: <4tslj8F15lqooU2@mid.individual.net>


On 08.12.2006 09:06, RJ wrote:
> Hi All,
>
> I have a table (table1) with 2 columns (ID, keywords)
> The ID column is the PK (values 1..n), and the keywords column is
> varchar with words separated with a space. EG:
>
> ID KEYWORD
> ---- -----------------
>
> 1 CAR VEHICLE
> 2 CHICKEN FOOD CUISINE
> 3 HOUSE PROPERTY CONSTRUCTION
>
> I need to separate the words to show like this:
>
> ID KEYWORD
> ----- -----------------
>
> 1 CAR
> 1 VEHICLE
> 2 CHICKEN
> 2 FOOD
> 2 CUISINE
>
> etc..
>
> how can this be done in SQL? I know i can use the UNION command to show
> each record, but how do I separate each word? I've tried using a
> combination of Instr and substr but its not showing correctly.

IMHO this is a typical case of bad data modeling. I would want to correct that. I'd probably write a script that extracts the data and writes out the proper separated values to a CSV file. Then I'd change the table layout or constraints (depending on what's there and how it's used) and import the data.

Kind regards

        robert Received on Fri Dec 08 2006 - 02:20:49 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US