我有一个非常大的数据集。我想要做的是根据标准动态创建列名。示例如下:
Key Type
cust1 Red
cust1 Blue
cust1 Yellow
cust2 Red
cust2 Blue
cust2 Green
Type Prob中会有更多数据,例如100种不同的颜色类型。当我查询结构看起来如下所示。列和数据
Key Red Blue Yellow Green
cust1 Red Blue Yellow
cust2 Red Blue Green
如果我写下如下的问题TOM代码:
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)