[Oracle新手教程] 用PL/SQL畫長條圖

來源:互聯網
上載者:User

現在用的庫裡有一個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.--------------------------------------------------------------------------------

  • 1
  • 2
  • 下一頁
【內容導航】
第1頁:[Oracle新手教程] 用PL/SQL畫長條圖 第2頁:[Oracle新手教程] 用PL/SQL畫長條圖

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.