您的位置:程序门 -> oracle -> 开发



高手帮忙写个存储过程,想了办天也想不出来?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


高手帮忙写个存储过程,想了办天也想不出来?
发表于:2007-12-23 23:42:49 楼主
2、不定列行列转换  
如  
c1   c2  
--------------  
1   我  
1   是  
1   谁  
2   知  
2   道  
3   不  
……  

转换为  
1   我是谁  
2   知道  
3   不  
用dbms_output输出每一行.


发表于:2007-12-23 23:50:561楼 得分:0
以下为创建的表
create   table   tt1

    c1   number,
    c2   char(2)
);

insert   into   tt1   (c1,   c2)
values   (1,   '我');
insert   into   tt1   (c1,   c2)
values   (1,   '是');
insert   into   tt1   (c1,   c2)
values   (1,   '谁');
insert   into   tt1   (c1,   c2)
values   (2,   '知');
insert   into   tt1   (c1,   c2)
values   (2,   '道');
insert   into   tt1   (c1,   c2)
values   (3,   '不');
commit;
请高手帮助想下,在线等
发表于:2007-12-24 00:04:572楼 得分:0
create   or   replace   procedure   irregular_switch
as
      max_xh   number;
      xh           number;
      str   varchar2(4000);
begin
    select   max(c1)   into   max_xh   from   tt1;
    for   xh   in   1..max_xh   loop
      for   c   in   (select   *   from   tt1   where   c1=xh)   loop
        str:=str ¦ ¦c.c2;
      end   loop;
      dbms_output.put_line(xh   ¦ ¦'     ' ¦ ¦str);
      str:='';
    end   loop;
end   ;

这种办法自己感觉不是太好.


快速检索

最新资讯
热门点击