pl⼀sql中求同一张表上下两行同一列的两条数据的时间差

如题:求出上下两条数据相差多少分钟
2025-05-09 08:37:19
推荐回答(2个)
回答1:

create table ttt as
select sysdate a,1 b , null c from dual
union all
select sysdate+1/24/60 a,2 b , null c from dual
union all
select sysdate+2/24/60 a,3 b , null c from dual
a 时间
b id
c 相差分钟

create or replace procedure p_test715 as
begin
for cr in (select a.rowid,b.a
from ttt a,ttt b
where a.b-1=b.b )
loop
update ttt
set c=(a-cr.a)*24*60
where rowid=cr.rowid;
END LOOP;
COMMIT;
end;

回答2:

selet (a- lead (a,a))*24*60 over (order by a)  from table_name