如何跟踪在SQL Developer中执行某些操作所需的时间

时间:2012-05-07 15:50:56

标签: oracle plsql timing procedure

基本上我是在一个程序中这样做的:

DECLARE
 CURSOR r_cursor is SELECT * from imp_exp.results where code = 8223558 FOR  UPDATE OF c_timestamp;

 BEGIN

 FOR idx IN r_cursor LOOP
   --dbms_output.put_line(idx.sample_code);
   update imp_exp.results set c_timestamp = TO_DATE('10-MAY-99', 'DD-MON=YY')    
WHERE CURRENT OF r_cursor;

END LOOP;

END;

如何显示这需要多长时间?谢谢!

2 个答案:

答案 0 :(得分:5)

set timing on
begin
  call_your_procedure;
end;

这将产生:

anonymous block completed
Elapsed: 00:00:05.524

答案 1 :(得分:2)

您也可以选择使用DBMS_UTILITY.get_time

DECLARE
    CURSOR r_cursor IS
      SELECT *
      FROM   imp_exp.results
      WHERE  code = 8223558
      FOR UPDATE OF c_timestamp;
    v_start_time NUMBER;
    v_end_time   NUMBER;
BEGIN
    v_start_time := DBMS_UTILITY.get_time;

    FOR idx IN r_cursor LOOP
        --dbms_output.put_line(idx.sample_code);
        UPDATE imp_exp.results
        SET    c_timestamp = To_date('10-MAY-99', 'DD-MON=YY')
        WHERE  CURRENT OF r_cursor;
    END LOOP;

    v_end_time := DBMS_UTILITY.get_time;

    dbms_output.Put_line('Elapsed time in seconds: '
                         || (v_end_time - v_start_time ) / 100);
END;