查询一个语句想知道这次查询用了多少时间
时间可以精确到1/1000000秒,我一直使用下面的方法:
CREATE OR REPLACE PACKAGE timing AS
PROCEDURE starttiming;
PROCEDURE stoptiming;
PROCEDURE printelapsed(p_message IN VARCHAR2);
END;
/
CREATE OR REPLACE PACKAGE BODY timing AS
v_starttime NUMBER;
v_endtime NUMBER;
PROCEDURE starttiming IS
BEGIN
SELECT to_number(to_char(systimestamp, 'ssxff'))
INTO v_starttime
FROM dual;
END;
PROCEDURE stoptiming IS
BEGIN
SELECT to_number(to_char(systimestamp, 'ssxff'))
INTO v_endtime
FROM dual;
END;
PROCEDURE printelapsed(p_message IN VARCHAR2) IS
v_elapsed NUMBER := v_endtime - v_starttime;
BEGIN
dbms_output.put_line('Elapsed Time for ' || p_message || ' is ' ||
v_elapsed || ' seconds.');
END;
END;
/
example:
timing.starttiming;
sql....
timing.stoptiming;
timing.printelapsed('test1');
时间可以精确到1/1000000秒,我一直使用下面的方法:
CREATE OR REPLACE PACKAGE timing AS
PROCEDURE starttiming;
PROCEDURE stoptiming;
PROCEDURE printelapsed(p_message IN VARCHAR2);
END;
/
CREATE OR REPLACE PACKAGE BODY timing AS
v_starttime NUMBER;
v_endtime NUMBER;
PROCEDURE starttiming IS
BEGIN
SELECT to_number(to_char(systimestamp, 'ssxff'))
INTO v_starttime
FROM dual;
END;
PROCEDURE stoptiming IS
BEGIN
SELECT to_number(to_char(systimestamp, 'ssxff'))
INTO v_endtime
FROM dual;
END;
PROCEDURE printelapsed(p_message IN VARCHAR2) IS
v_elapsed NUMBER := v_endtime - v_starttime;
BEGIN
dbms_output.put_line('Elapsed Time for ' || p_message || ' is ' ||
v_elapsed || ' seconds.');
END;
END;
/
example:
timing.starttiming;
sql....
timing.stoptiming;
timing.printelapsed('test1');