常用SQL性能统计代码
2015-03-13 15:27 钟铧若岩 阅读(215) 评论(0) 编辑 收藏 举报
1 BEGIN 2 DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=> 'TELEDB', TABNAME=> 'WFGTEST', PARTNAME=> NULL); 3 END; 4 ALTER TABLE WFGTEST DEALLOCATE UNUSED ; 5 COMMIT; 6 7 SELECT TABLE_NAME,NUM_ROWS,BLOCKS,EMPTY_BLOCKS 8 FROM USER_TABLES 9 WHERE TABLE_NAME='WFGTEST'; 10 11 SELECT COUNT(1) FROM WFGTEST; 12 13 DELETE FROM WFGTEST; 14 COMMIT; 15 16 TRUNCATE TABLE WFGTEST; 17 COMMIT; 18 19 SELECT *FROM WFGTEST; 20 21 DECLARE 22 NUM NUMBER(20); 23 DT1 DATE; 24 BEGIN 25 NUM :=1; 26 DT1 := SYSDATE(); 27 FOR NUM IN 1 .. 1000000 28 LOOP 29 INSERT INTO WFGTEST VALUES(TO_CHAR(NUM),TO_CHAR(NUM),NUM); 30 END LOOP; 31 COMMIT; 32 33 DBMS_OUTPUT.PUT_LINE(FLOOR(TO_NUMBER(SYSDATE-DT1)*24*60*60)); 34 35 END ;