计算运行过程的持续时间(Oracle、PL/SQL)

问题描述 投票:0回答:1

我有一些 PL/SQL 块代码正在更新。表格有很多数据,我想计算一下花了多长时间。

declare
 cursor c1 is select * from my_Table;
 my_record.my_Table%rowtype;
 startDate DATE;
 endDate DATE;
begin
 SELECT SYSDATE into startDate FROM dual;
  open c1;
    loop fetch c1 into my_record; 
      exit when c1%notfound;      
       --some updates
      
    end loop;
   --commit;
  close c1;
  SELECT SYSDATE into endDate FROM dual;
  DBMS_OUTPUT.PUT_LINE(startDate - endDate);
end;

当我跑步时,我得到了奇怪的值:

-,00001157407407407407407407407407407407407407
oracle date datetime timestamp difference
1个回答
0
投票

您可以按如下方式更新您的

DBMS_OUTPUT

DBMS_OUTPUT.PUT_LINE(ROUND(endDate - startDate),2); --> Days
DBMS_OUTPUT.PUT_LINE(ROUND((endDate - startDate) * 24, 2)); --> Hours
DBMS_OUTPUT.PUT_LINE(ROUND((endDate - startDate) * 24 * 60, 2); --> minutes
DBMS_OUTPUT.PUT_LINE(ROUND((endDate - startDate) * 24 * 60 * 60, 2)); --> seconds
© www.soinside.com 2019 - 2024. All rights reserved.