现在的位置: 首页 > 综合 > 正文

关于行列转置的实现方法

2013年12月11日 ⁄ 综合 ⁄ 共 518字 ⁄ 字号 评论关闭

1、固定列数的行列转换

student subject grade

--------- ---------- --------

student1 80

student1 数学 70

student1 60

student2 90

student2 数学 80

student2 100

……

转换为

文 数学 英

student1 80 70 60

student2 90 80 100

……

句如下:select student,

sum(decode(subject,'', grade,null)) "",

sum(decode(subject,'数学', grade,null)) "数学",

sum(decode(subject,'', grade,null)) ""

from table

group by student;

 

 

2、不定列行列转换

c1 c2

--- -----------

1

1

1

2

2

3

……

转换为

1 我是

2 知道

3

 

型的转换可以借助于PL/SQL来完成,一个例子

CREATE OR REPLACE FUNCTION get_c2(tmp_c1 NUMBER)

RETURN VARCHAR2

IS

Col_c2 VARCHAR2(4000);

BEGIN

FOR cur IN (

抱歉!评论已关闭.