Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Concatenate the result of a sub select...

715700Nov 30 2009 — edited Nov 30 2009
OK, here's my problem. I have 2 tables, one referring to the other. Several rows from table B belong to table's A datas and I'd like to make a select where I can "concatenate" the content of table's B datas in one of my select row.
So for, here's what I've done:
select distinct d.code,
  c.libe "Nom",
  d.ddeb "Date de dépot",
  d.nume "Numéro de demande",
  (select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=1
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=2
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=3
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=4
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=5
  ) "type",
  (select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=1
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=2
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=3
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=4
  )
  ||' '
  ||
  (select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=5
  ) "Commune"
from demandeur d,
  demande t,
  client c
where t.code=d.nume
and c.code  =d.code
and c.role  ='1'
and t.natu  ='T'
and dfin   is null
and ddeb    <'30/09/2008'
and clot   is null
and d.nume in
  (select u.code from demande u where u.libe in ('F1','F 1bis','F2','F3')
  )
order by d.ddeb asc ;
The problem is that this methode will only display the five first rows in table B (demande). In table B, there might be between 1 and up to 14 rows for "Commune" and up to 10 rows for "Type".

Would there be any cleaner or smarter method to do this ?

thx
This post has been answered by 730428 on Nov 30 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 28 2009
Added on Nov 30 2009
6 comments
333 views