由于旧系统的愚蠢限制,我试图使用一个语句编写以下查询:
insert into dbo.mytable_archive
select *
from dbo.mytable
where date < trunc(sysdate) - 14;
delete from dbo.mytable
where date < trunc(sysdate) - 14;
Run Code Online (Sandbox Code Playgroud)
利用Google的强大功能,我发现使用RETURNINGPostgres OUTPUT子句或SQLServer中的子句在许多其他数据库中似乎可行,但是我找不到Oracle(V12)的等效解决方案。
有解决方法的主意吗?
如果您的声明在午夜左右运行并且可能花费超过1秒的时间,则最好执行以下操作:
create or replace procedure move_to_arch as
theDate DATE := trunc(sysdate) - 14;
begin
insert into dbo.mytable_archive
select *
from dbo.mytable
where date < theDate ;
delete from dbo.mytable
where date < theDate ;
commit;
end;
/
Run Code Online (Sandbox Code Playgroud)