估计运行时间(Db2)

bihw5rsg  于 2022-12-04  发布在  DB2
关注(0)|答案(1)|浏览(122)

我想计算DB2LUW中脚本的运行时间,需要编写代码以获得开始时间和结束时间,然后返回两者的差值。

select current timestamp as startdate from sysibm.sysdummy1;

-- my querys

select current timestamp as enddate from sysibm.sysdummy1;

select timestampdiff (enddate , startdate);
bbuxkriu

bbuxkriu1#

首先,您错误地使用了timestampdiff()--请检查the manual
第二,你不能在Db2中从无到有地select;您似乎知道如何使用sysibm.sysdummy1,因此可以将相同的技术应用于已用时间的计算。
但最糟糕的是,您没有将select current timestamp...查询的结果保存到任何地方,因此以后无法引用它们。
如果您不想编写SQL/PL代码,可以执行以下操作:

create table t (starttime timestamp, endtime timestamp);
-- you could also declare a global temporary table instead

insert into t (starttime) values (current timestamp);

-- your statements

update t set endtime=current timestamp;
select timestampdiff(1, char(endtime-starttime)) as elapsed_microseconds from t;
drop table t; -- if it's not a temp table

相关问题