Search code examples
oracle-databaseoracle11gsystemcoordinatecartesian

oracle show table like cartesian coordinate system


I have a table

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

with filling a table as

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;

how I can show table like

    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

where x - rows, y - columns, svalue - value x,y


Solution

  • if we want to get pivot output for Cartesian coordinate system

    run below script for create pivot function http://paste.ubuntu.com/21378705/

    pivot function is actually ref cursor that give dynamic column output after ruining above script run query as

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

    in above query select statement use as following manner

    select rowsection,columnsection,data from table     
    

    i hope this will help.