select - Get multiple data into one colomn Oracle Query -


i have 3 tables: table_a, table_b , table_c. table_a has primary key , referred foreign key table_b. table_c has primary key referred foreign key table_b. design this:

 table_a: id_a textdata 
 table_b: id_b id_a id_c 
 table c: id_c textdata 

i want join between 3 tables this:

 select a.id_a, a.textdata dataa,  (   select c.textdata   table_b b, table_c c    b.id_c = c.id_c , b.id_a = c.id_a ) data_c table_a; 

i know should error if try compile error like: return more 1 elements.

but client want me join data table c 1 row, know using concate every data. don't know how it. never try create function or package on oracle. can me how fix query?

the result should like:

 id_a    | dataa     | data_c 1         texta       text1, text2, text8 2         textb       text2, text3, text9 3         textc       text1, text8, text9 

xmlagg or similar need. (not tested, should give hint):

select a.id_a, a.textdata dataa,  (   select xmlelement("thedata",xmlagg("textdata",c.textdata)) td   table_b b, table_c c    b.id_c = c.id_c , b.id_a = c.id_a ) data_c table_a;  

use replace/translate/regexp_replace etc strip out xml tags if required.

loads of example e.g. http://www.dba-oracle.com/t_converting_rows_columns.htm .


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -