oracle show table 类笛卡尔坐标系
oracle show table like cartesian coordinate system
我有一个table
create table test_table(
id number(10),
x number(10),
y number(10),
svalue number(10));
用填充一个table作为
declare
i integer;
begin
i := 0;
for x in 1 .. 10 loop
for y in 1 .. 10 loop
i := i + 1;
insert into test_table
(Id, x, y, svalue)
values
(i, x, y, x + y);
end loop;
end loop;
commit;
end;
如何让 table 像
1 2 3 4 5 Ny
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
Nx
其中 x - 行,y - 列,svalue - 值 x,y
听说我使用循环实现笛卡尔坐标系test_table。
declare
HEAD VARCHAR2(100);
CURSOR c1 IS SELECT distinct x rec FROM test_table order by x;
CURSOR c2 IS SELECT distinct y rec FROM test_table order by y;
begin
-- for disply header in y
for y in c2 loop
HEAD := HEAD || lpad(y.rec,4);
end loop;
DBMS_OUTPUT.put_line( lpad('X',3) || HEAD );
--
-- disply value with repect to x and y
for x in c1 loop
declare
STR VARCHAR2(100);
CURSOR c2 IS SELECT svalue rec FROM test_table where x= x.rec order by y;
begin
for y in c2 loop
STR := str || lpad(y.rec,4);
end loop;
DBMS_OUTPUT.put_line(lpad(x.rec,3) || STR);
end;
end loop;
--
end;
希望对您有所帮助。
如果我们想要获得笛卡尔坐标系的枢轴输出
运行 下面的脚本用于创建数据透视函数
http://paste.ubuntu.com/21378705/
pivot 函数实际上是 ref cursor,它在破坏上述脚本后给出动态列输出 运行 query as
select * from table(pivot('select x,y,svalue from test_table'))
在上面的查询select语句中使用如下方式
select rowsection,columnsection,data from table
希望对您有所帮助。
我有一个table
create table test_table(
id number(10),
x number(10),
y number(10),
svalue number(10));
用填充一个table作为
declare
i integer;
begin
i := 0;
for x in 1 .. 10 loop
for y in 1 .. 10 loop
i := i + 1;
insert into test_table
(Id, x, y, svalue)
values
(i, x, y, x + y);
end loop;
end loop;
commit;
end;
如何让 table 像
1 2 3 4 5 Ny
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
Nx
其中 x - 行,y - 列,svalue - 值 x,y
听说我使用循环实现笛卡尔坐标系test_table。
declare
HEAD VARCHAR2(100);
CURSOR c1 IS SELECT distinct x rec FROM test_table order by x;
CURSOR c2 IS SELECT distinct y rec FROM test_table order by y;
begin
-- for disply header in y
for y in c2 loop
HEAD := HEAD || lpad(y.rec,4);
end loop;
DBMS_OUTPUT.put_line( lpad('X',3) || HEAD );
--
-- disply value with repect to x and y
for x in c1 loop
declare
STR VARCHAR2(100);
CURSOR c2 IS SELECT svalue rec FROM test_table where x= x.rec order by y;
begin
for y in c2 loop
STR := str || lpad(y.rec,4);
end loop;
DBMS_OUTPUT.put_line(lpad(x.rec,3) || STR);
end;
end loop;
--
end;
希望对您有所帮助。
如果我们想要获得笛卡尔坐标系的枢轴输出
运行 下面的脚本用于创建数据透视函数 http://paste.ubuntu.com/21378705/
pivot 函数实际上是 ref cursor,它在破坏上述脚本后给出动态列输出 运行 query as
select * from table(pivot('select x,y,svalue from test_table'))
在上面的查询select语句中使用如下方式
select rowsection,columnsection,data from table
希望对您有所帮助。