1

I have a very very large dataset. What I want to do is dynamically create column names based on criteria. Example Below:

   Key         Type 
   cust1       Red
   cust1       Blue
   cust1       Yellow
   cust2       Red
   cust2       Blue
   cust2       Green

There will be much more data in Type Prob like 100 different color types. When I query structure to look like the below. Columns and Data

Key     Red Blue Yellow Green
cust1   Red Blue Yellow
cust2   Red Blue        Green

if I write the ask TOM code like the below:

procedure go_fishing( p_cursor in out t_cursor)
as
l_query long := 'select fish_id';
begin
    for x in (select distinct fish_type from fish order by 1 )
    loop
        l_query := l_query ||
           replace( q'|, sum(decode(fish_type,'$X$',fish_weight)) $X$|', '$X$',
                   dbms_assert.simple_sql_name(x.fish_type) );
   end loop;

   l_query := l_query || ' from fish group by fish_id order by fish_id';

   open p_cursor for l_query;

  end;



How can I execute it? exec goFishing_pkg.go_fishing(:x)
codeMonger123
  • 505
  • 5
  • 13

0 Answers0