注册
存储过程如何打印其中单条SQL的执行时间
技术分享/ 文章详情 /

存储过程如何打印其中单条SQL的执行时间

Solreal 2026/07/31 184 0 0

在结果集中打印执行效果

--打印执行时间 print now()||'时间1.2'; select count(1) into tcount from bippaytask where batchno = p_batchno and systemid = p_systemid; if tcount <> p_count or p_count = 0 then raise_application_error(-20002, '任务条数不正确');

将每条执行SQL的时间插入到某张表中

1、创建示例表

CREATE TABLE "ttt" ( "COL1" VARCHAR2(100), "COL2" VARCHAR2(100), "COL3" TIMESTAMP ) ;

2、每条SQL执行前添加一条插入语句

insert into ttt VALUES ('', '1.2', SYSDATE()); commit; select count(1) into tcount from bipsysinfo where id = p_systemid; if tcount <> 1 then raise_application_error(-20001, '接入系统不存在'); end if;

或者

在存储过程中定义一个函数,每个SQL之前单独定义时间,这样多次执行可以根据时间区分

---表结构 CREATE TABLE ttt ( col1 VARCHAR2(100), col2 VARCHAR2(100), col3 VARCHAR2(100), col4 DATE ) ; --存储过程中修改 procedure paycheck(p_batchno varchar2, p_systemid varchar2, p_count integer, p_policy varchar2 ) is tcount integer; tlockparam integer; tchkhashdefault varchar2(1); tchkdays integer; tchkthresholdminutes integer; tt TIMESTAMP; --在存储过程中添加函数 begin set tt=SYSDATE();--打印时间 select count(1) into tcount from bipsysinfo where id = p_systemid; if tcount <> 1 then raise_application_error(-20001, '接入系统不存在'); end if; insert into ttt VALUES ('', tt,'1.2', SYSDATE());将结果插入到指定表中 commit;
评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服