现在用的库里有一个MV是统计按小时的访问量的,数据如下代码:
SQL> select * from mv_time_stat;
TIME CNT
---------- ----------
0 187
1 51
2 34
3 19
4 19
5 20
6 50
7 107
8 682
9 1342
10 1854
11 1292
12 1416
13 1180
14 1217
15 1573
16 1785
17 1469
18 1892
19 1907
20 1602
21 1540
22 1013
23 441
24 rows selected.
--------------------------------------------------------------------------------
某年月日,突发奇想,打算在sqlplus下面按上面的数据画个直方图出来,首先写了个竖列的(因为好写):
代码:--------------------------------------------------------------------------------
SQL> COL Time FORMAT A7
SQL> SELECT LPAD(DECODE(TIME,TO_CHAR(SYSDATE,'HH24'),'NOW: '||TO_CHAR(TIME),TO_CHAR(TIME)),7,' ') AS "Time",
2 SUBSTR('|'||LPAD('> '||CNT,CEIL(CNT/A.TOTAL*300)+LENGTH(TO_CHAR(CNT))+1,'-'),1,35) AS " Count per hour"
3 FROM MV_TIME_STAT,(SELECT SUM(CNT) AS TOTAL FROM MV_TIME_STAT) A;
COL Time CLEAR
Time Count per hour
------- -----------------------------------------------------------------
0 |--> 187
1 |> 51
2 |> 34
3 |> 19
4 |> 19
5 |> 20
6 |> 50
7 |-> 107
NOW: 8 |---------> 682
9 |-----------------> 1342
10 |------------------------> 1854
11 |-----------------> 1292
12 |------------------> 1416
13 |---------------> 1180
14 |----------------> 1217
15 |--------------------> 1573
16 |-----------------------> 1785
17 |-------------------> 1469
18 |-------------------------> 1892
19 |-------------------------> 1907
20 |---------------------> 1602
21 |--------------------> 1540
22 |-------------> 1013
23 |-----> 441
24 rows selected.--------------------------------------------------------------------------------
当前位置: 数据库>oracle
[Oracle新手教程] 用PL/SQL画直方图
来源: 互联网 发布时间:2017-03-17
本文导语: 现在用的库里有一个MV是统计按小时的访问量的,数据如下代码: SQL> select * from mv_time_stat; TIME CNT---------- ---------- 0 187 1 51 2 34 3 19 4 19 5 20 6 ...