根据年龄或日期从 Oracle 表中删除数百万行的脚本
是否有可能在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于在单个事务中删除了这么多行,您还应该预测将使用大量撤消空间。您删除的所有行都将短暂保存在撤消表空间中,以便您回滚事务,更重要的是,允许其他用户在您提交删除之前查看这些行。请参阅此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.
由于
FEED_DT_TM
是DATE
,因此无需使用TO_DATE
将其转换为DATE
。简单地Since
FEED_DT_TM
is aDATE
, there is no need to useTO_DATE
to cast it to aDATE
. Simply还可以考虑将所需的行保留在新表中,然后删除旧表的选项。
就像......
确保您还查看约束、索引和其他对象(如果适用于初始表)。并且不要忘记测试、测试、测试。
Also consider the option of keeping the rows you need in a new table and then dropping the old table.
Something like..
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.