日期:2014-05-17  浏览次数:21100 次

oracle 10g 行转列(动态列)
如题,大家一般都是怎么解决这个问题的?

------解决方案--------------------
以前写的  动态行转列  其实行列转换类型都差不多
create or replace procedure p1 is
Cursor cursor is select t.column_name cn
  from user_col_comments t
  where t.table_name = upper('t1') and t.column_name <> 'y';
  sqlstr varchar2(4000);
begin
  for c_name in cursor loop 
  begin
  sqlstr := sqlstr + ' select '
------解决方案--------------------
c_name.cn
------解决方案--------------------
',decode(t1.y,2009,(select '
------解决方案--------------------
c_name.cn
------解决方案--------------------
' from t1 where y=2009),0) cc from t1 union all ';
  DBMS_OUTPUT.PUT_LINE(sqlstr);
  end;
  end loop;
  --EXECUTE IMMEDIATE (sqlstr);
end p1;