How to view the execution time of a SQL query in PL/SQL…

In PL/SQL, you can use the TIMER in the DBMS_UTILITY package to measure the execution time of SQL statements. Here is an example:

DECLARE
  start_time NUMBER;
  end_time NUMBER;
  elapsed_time NUMBER;
BEGIN
  start_time := DBMS_UTILITY.GET_TIME;
  
  -- 执行你的SQL语句
  -- ...
  
  end_time := DBMS_UTILITY.GET_TIME;
  elapsed_time := end_time - start_time;
  
  DBMS_OUTPUT.PUT_LINE('执行时间:' || elapsed_time || '微秒');
END;

In the above example, the start time and end time are first obtained using the function DBMS_UTILITY.GET_TIME, then the difference between the two is calculated to get the execution time. Finally, the execution time is output using the function DBMS_OUTPUT.PUT_LINE.

Please note that the DBMS_UTILITY.GET_TIME function returns microseconds from a fixed point in time. The time unit may vary among different database versions, so conversion may be necessary based on the specific situation.

bannerAds