菜鸟学oracle - 用PL/SQL画直方图
2007-05-12 12:22:48 来源:WEB开发网核心提示: 然后又想,怎么样把它横过来,到网上查资料,又突击学习了下分析函数,写了一个过程是这个样子的:代码:CREATE OR REPLACE PROCEDURE HISTOGRAPH(HEIGHT NUMBER DEFAULT 15) ASMAX_ONE NUMBER;STR_LINE VARCH
然后又想,怎么样把它横过来,到网上查资料,又突击学习了下分析函数,写了一个过程是这个样子的:
代码:
CREATE OR REPLACE PROCEDURE HISTOGRAPH(HEIGHT NUMBER DEFAULT 15) AS
MAX_ONE NUMBER;
STR_LINE VARCHAR(120);
STR_TEMP VARCHAR(120);
I NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(LPAD('^',14,' '));
SELECT MAX(CNT) INTO MAX_ONE FROM MV_TIME_STAT;
FOR I IN 1 .. HEIGHT+1 LOOP
STR_LINE:=LPAD(TO_CHAR(MAX_ONE-(I-1)*MAX_ONE/HEIGHT,'99999')||'-'||TO_CHAR(MAX_ONE-(I-2)*MAX_ONE/HEIGHT,'99999')||'|',14,'0');
SELECT MAX(SYS_CONNECT_BY_PATH(
DECODE(SIGN(CNT-MAX_ONE+(I-1)*MAX_ONE/HEIGHT),-1,
DECODE(SIGN(CNT-MAX_ONE+(I-2)*MAX_ONE/HEIGHT),-1,'^','*'),
'|'),
' ')) INTO STR_TEMP
FROM MV_TIME_STAT
START WITH TIME=0
CONNECT BY PRIOR TIME=TIME-1;
STR_LINE:=STR_LINE||STR_TEMP;
DBMS_OUTPUT.PUT_LINE(REPLACE (STR_LINE,'^',' '));
END LOOP;
SELECT MAX(SYS_CONNECT_BY_PATH(TO_CHAR(TIME,'00'),'^')) INTO STR_TEMP
FROM MV_TIME_STAT
START WITH TIME=0
CONNECT BY PRIOR TIME=TIME-1;
DBMS_OUTPUT.PUT_LINE(LPAD('0',14,' ')||LPAD('>',LENGTH(REPLACE(STR_TEMP,' '))+3,'-'));
DBMS_OUTPUT.PUT_LINE(REPLACE(LPAD('^',14,' ')||REPLACE(STR_TEMP,' '),'^',' '));
END;
/
Procedure created.
SQL> exec histograph;
^
1907- 2034| |
1780- 1907| | | | |
1653- 1780| | | | |
1526- 1653| | | | | | | |
1398- 1526| | | | | | | | | |
1271- 1398| | | | | | | | | | | |
1144- 1271| | | | | | | | | | | | | |
1017- 1144| | | | | | | | | | | | | |
890- 1017| | | | | | | | | | | | | | |
763- 890| | | | | | | | | | | | | | |
636- 763| | | | | | | | | | | | | | | |
509- 636| | | | | | | | | | | | | | | |
381- 509| | | | | | | | | | | | | | | | |
254- 381| | | | | | | | | | | | | | | | |
127- 254| | | | | | | | | | | | | | | | | |
0- 127| | | | | | | | | | | | | | | | | | | | | | | | |
0-------------------------------------------------------------------------->
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23
PL/SQL procedure successfully completed.
自己感觉应该还可以用一条语句实现,不过偷懒了。。
发上来大家共享,顺便抛砖引玉,各位大牛不吝赐教。
- ››oracle 中 UPDATE nowait 的使用方法
- ››Oracle ORA-12560解决方法
- ››Oracle 10g RAC 常用维护命令
- ››Oracle如何在ASM中定位文件的分布
- ››Oracle的DBMS_RANDOM.STRING 的用法
- ››oracle 外部表导入时间日期类型数据,多字段导入
- ››Oracle中查找重复记录
- ››oracle修改用户登录密码
- ››Oracle创建删除用户、角色、表空间、导入导出等命...
- ››Oracle中登陆时报ORA-28000: the account is lock...
- ››Oracle数据库在配置文件中更改最大连接数
- ››Oracle中在pl/sql developer修改表的两种方式
更多精彩
赞助商链接