Re: Tricky SQL question

From: Petre Alexandrescu <Petre.Alexandrescu_at_mci.com>
Date: 1998/11/04
Message-ID: <Sp202.374$t53.5205_at_news.cwix.com>#1/1


Select Person, ID, get_attributes(ID) from PERSONS;

where get_attributes is a stored function as following:

function get_attributes(pers_id in PERSONS.ID%TYPE) return varchar2 is begin

read in a cursor all attributes for pers_id and concatenate them in a string

return string;

end;

Joost Ouwerkerk wrote in message
<3640a959.4517586_at_resunix.sickkids.on.ca>...
>Given two tables: people (Person, ID) and attributes (ID, attribute)
>
>A person can have any number of attributes:
>
>ID Attribute
>--- ---------
>123 Man
>123 Actor
>123 Consumer
>
>How can I get the following output using only SQL (SQL*Plus):
>
>Person ID Attributes
>-------------------------- --- ---------------------------------
>Joe Jones 123 Man, Actor, Consumer
>Mary Walsh 234 Woman, Comedian, Writer, Director
>Jackie Chan 456 Man, Martial Artist
>Larry Sanders 678 Man, Comedian, Producer
>
>The attributes must be on one line and separated by commas. Is this
>even possible?
>
>Joost Ouwerkerk
>Hospital For Sick Children Foundation
>Toronto, Canada
Received on Wed Nov 04 1998 - 00:00:00 CET

Original text of this message