gpt4 book ai didi

sql - 在 Oracle 中使用单个语句在表之间移动行

转载 作者:行者123 更新时间:2023-12-04 23:40:04 25 4
gpt4 key购买 nike

由于愚蠢的遗留系统限制,我尝试使用单个语句编写以下查询:

insert into dbo.mytable_archive 
select *
from dbo.mytable
where date < trunc(sysdate) - 14;

delete from dbo.mytable
where date < trunc(sysdate) - 14;

使用 Google 的强大功能,我发现这在许多其他使用 RETURNING 的数据库中似乎是可能的。第 i 条 Postgres 或 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;
/

关于sql - 在 Oracle 中使用单个语句在表之间移动行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40397406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com