本帖最后由 hongqishi 于 2009-10-18 18:55:03 编辑

解决方案 »

  1.   


    参考这个帖子写过程
    http://topic.csdn.net/u/20091018/15/7c6729b6-79d1-492e-862d-af9c4921f172.html?seed=524755432&r=60497764#r_60497764把group by省了
    字段名和字段值看着有点别扭..
    重复的怎么处理?
      

  2.   

    drop table sm_user;
    create table sm_user as
      select chr(rownum+64) name from dual
      connect by rownum<27;create or replace proc
    as
    declare
    sqlstr varchar2(2000):='select ';
    i number:=1;
    begin
      for cur1 in (select name from sm_user)
      loop
        sqlstr:=sqlstr||'
      max(decode(rownum,'||i||',name))"'||cur1.name||'",';
      i:=i+1;
      end loop;
      sqlstr:=rtrim(sqlstr,',')||'
      from sm_user';
      dbms_output.put_line(sqlstr);
    end;--生成结果
    select 
      max(decode(rownum,1,name))"A",
      max(decode(rownum,2,name))"B",
      max(decode(rownum,3,name))"C",
      max(decode(rownum,4,name))"D",
      max(decode(rownum,5,name))"E",
      max(decode(rownum,6,name))"F",
      max(decode(rownum,7,name))"G",
      max(decode(rownum,8,name))"H",
      max(decode(rownum,9,name))"I",
      max(decode(rownum,10,name))"J",
      max(decode(rownum,11,name))"K",
      max(decode(rownum,12,name))"L",
      max(decode(rownum,13,name))"M",
      max(decode(rownum,14,name))"N",
      max(decode(rownum,15,name))"O",
      max(decode(rownum,16,name))"P",
      max(decode(rownum,17,name))"Q",
      max(decode(rownum,18,name))"R",
      max(decode(rownum,19,name))"S",
      max(decode(rownum,20,name))"T",
      max(decode(rownum,21,name))"U",
      max(decode(rownum,22,name))"V",
      max(decode(rownum,23,name))"W",
      max(decode(rownum,24,name))"X",
      max(decode(rownum,25,name))"Y",
      max(decode(rownum,26,name))"Z"
      from sm_user
      

  3.   

    create or replace proc
    as
    这句去掉..