根据年龄或日期从 Oracle 表中删除数百万行的脚本

发布于 2024-12-27 10:52:21 字数 125 浏览 1 评论 0原文

是否有可能在 oracle 中编写一个脚本,根据年龄从表中删除行。即,我想删除行 s。我有一个包含数百万行的表,我只想保留最近 3 个月的行。我有下表,其中包含列名称,因为

我对数据库内容非常陌生。我该如何为此编写脚本?

Is there a possiblity to write a script in oracle which deletes the rows from a table based on the age. i.e., I want to delete the rows s. I have a table with millions of rows in it and I want to keep only the latest 3 months rows. I have the following table with column names as

I am very new to database stuff. How can I write a script for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遗心遗梦遗幸福 2025-01-03 10:52:21

由于在单个事务中删除了这么多行,您还应该预测将使用大量撤消空间。您删除的所有行都将短暂保存在撤消表空间中,以便您回滚事务,更重要的是,允许其他用户在您提交删除之前查看这些行。请参阅此asktom 线程< /a> 寻求建议。

With this many rows deleted in a single transaction you should also predict that much undo space will be used. All the rows that you delete will be briefly saved in the undo tablespace to allow you to rollback transaction and, more importantly, to allow other users to see the rows until you COMMIT your delete. See this asktom thread for advice.

丶情人眼里出诗心の 2025-01-03 10:52:21

由于 FEED_DT_TMDATE,因此无需使用 TO_DATE 将其转换为 DATE。简单地

DELETE FROM your_table_name
 WHERE sysdate - feed_dt_tm >= 120

Since FEED_DT_TM is a DATE, there is no need to use TO_DATE to cast it to a DATE. Simply

DELETE FROM your_table_name
 WHERE sysdate - feed_dt_tm >= 120
沫雨熙 2025-01-03 10:52:21

还可以考虑将所需的行保留在新表中,然后删除旧表的选项。

就像......

create table new_table_2_months
as
select * 
  from table1
  where date_column > (sysdate-60)

drop table table1;

alter table new_table_2_months rename to table1;

确保您还查看约束、索引和其他对象(如果适用于初始表)。并且不要忘记测试、测试、测试。

Also consider the option of keeping the rows you need in a new table and then dropping the old table.

Something like..

create table new_table_2_months
as
select * 
  from table1
  where date_column > (sysdate-60)

drop table table1;

alter table new_table_2_months rename to table1;

Make sure you also look at constraints, indexes and other objects, if applicable to the initial table. And don't forget to TEST, TEST, TEST.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文