Oracle database experiences

Oracle database blog

Plotting graph with SQL*Plus – Part IV

Multi-curves

It is possible to modify the query described in the Part III in order to plot several curves in the same graph.

The following query will display the functions y=cos(x) and y=sin(x) for x belonging to [0.1,11] and y belonging to [-0.9,1.0].

SELECT y_axis,
  listagg(decode(y1_val,1,'*',2,'+','.'),'')  WITHIN GROUP (ORDER BY x_val) graph_val
FROM
  (SELECT tab_val.x_val,
    tab_y_axis.y_axis,
    decode(tab_y_axis.y_axis,tab_val.y_val1,1,tab_val.y_val2,2,0) y1_val
  FROM
    (SELECT LEVEL x_val,
      trunc(cos((LEVEL/10)),1) y_val1,
      trunc(sin((LEVEL/10)),1) y_val2
    FROM dual
      CONNECT BY LEVEL <= 110
    ) tab_val
  CROSS JOIN
    (SELECT trunc((LEVEL/10)-1,1) y_axis FROM dual CONNECT BY LEVEL <= 20
    ) tab_y_axis
  )
GROUP BY y_axis
ORDER BY 1 DESC;

Result

SQL> @plot_graph6
         1 ..............................................................................................................
        .9 ****.......+++++++++......................................*********.......+++++++++...........................
        .8 ....**...++.........++..................................**.........**...++.........+..........................
        .7 ......*++.............+...............................**.............*++............++........................
        .6 ......+**..............+.............................*...............+**..............+.......................
        .5 .....+...*..............++..........................*...............+...*..............++.....................
        .4 ....+.....*...............+........................*..............++.....*...............+....................
        .3 ...+.......*...............+......................*..............+........*...............+...................
        .2 ..+.........*...............+....................*..............+..........*...............+..................
        .1 .+...........*...............+..................*..............+............*...............+.................
         0 +.............**..............++..............**.............++..............**..............++.............**
       -.1 ................*...............+............*..............+..................*...............+...........*..
       -.2 .................*...............+..........*..............+....................*...............+.........*...
       -.3 ..................*...............+........*..............+......................*...............+.......*....
       -.4 ...................*...............+.....**..............+........................*...............+.....*.....
       -.5 ....................**..............+...*...............+..........................*...............+...*......
       -.6 ......................*..............++*...............+............................**..............++*.......
       -.7 .......................*.............**+.............++...............................*.............**+.......
       -.8 ........................**.........**...++.........++..................................**.........**...++.....
       -.9 ..........................*********.......+++++++++......................................*********.......+++++

20 rows selected.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: