【问题标题】:oracle show table like cartesian coordinate systemoracle show table 像笛卡尔坐标系
【发布时间】:2016-12-10 06:13:19
【问题描述】:

我有一张桌子

create table test_table(
id number(10),
x number(10),
y number(10),
svalue number(10));

填表为

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;

如何显示表格

    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

【问题讨论】:

  • 首先引用此 url stackoverflow.com/questions/38651147/… 并在创建数据透视函数后运行此查询 select * from table(pivot('select x,y,svalue from test_table'))
  • 我有 Oracle Database 11g Express Edition Release 11.2.0.2.0ORA-29913: error in execution ODCITABLEDESCRIBE callout
  • 如果您在维护问题时对数据进行表格化,那么它将起作用。
  • 我从一个问题运行代码并得到一个错误,我发现错误通常发生在 11.2.0.3 之前的版本中

标签: oracle oracle11g system coordinate cartesian


【解决方案1】:

如果我们想获得笛卡尔坐标系的枢轴输出

运行以下脚本以创建数据透视函数 http://paste.ubuntu.com/21378705/

pivot 函数实际上是引用游标,它在破坏上述脚本运行查询后给出动态列输出

select * from table(pivot('select x,y,svalue from test_table'))

在上面的查询选择语句中使用如下方式

select rowsection,columnsection,data from table     

我希望这会有所帮助。

【讨论】:

【解决方案2】:

听说我使用循环 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;

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 2020-07-05
    相关资源
    最近更新 更多