码迷,mamicode.com
首页 > 数据库 > 详细

使用pl/sql監控PROCEDURE執行時間

时间:2016-08-01 21:12:59      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

創建表

CREATE TABLE PROCESS_TIMING_LOG
(
  PROCESS_NAME       VARCHAR2(50 BYTE),
  EXECUTION_DATE     DATE,
  RECORDS_PROCESSED  NUMBER,
  ELAPSED_TIME_SEC   NUMBER
)

創建Procedure

CREATE OR REPLACE PROCEDURE SCOTT.update_salary
AS
   CURSOR cur_employee
   IS
      SELECT empno, sal, ROWID FROM EMPLOYEE_TEST;

   lv_new_salary_num   NUMBER;
   lv_count_num        PLS_INTEGER := 0;
   lv_start_time_num   PLS_INTEGER;
   lv_total_time_num   NUMBER;
BEGIN
   lv_start_time_num := DBMS_UTILITY.GET_TIME;

   FOR cur_employee_rec IN cur_employee
   LOOP
      lv_count_num := lv_count_num + 1;
      lv_new_salary_num := cur_employee_rec.sal;

      UPDATE employee_test
         SET sal= lv_new_salary_num
       WHERE ROWID = cur_employee_rec.ROWID;
   END LOOP;

   lv_total_time_num := (DBMS_UTILITY.GET_TIME - lv_start_time_num) / 100;

   INSERT INTO process_timing_log (process_name,
                                   execution_date,
                                   records_processed,
                                   elapsed_time_sec)
        VALUES (‘update_salary‘,
                SYSDATE,
                lv_count_num,
                lv_total_time_num);

   COMMIT;
END update_salary;
/
運行結果

PROCESS_NAME,EXECUTION_DATE,RECORDS_PROCESSED,ELAPSED_TIME_SEC
update_salary,2016/8/1 下午 02:57:08,4257554,532.28

使用pl/sql監控PROCEDURE執行時間

标签:

原文地址:http://www.cnblogs.com/guilingyang/p/5727009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!