如何在oracle中使用定时器执行程序

发布于 2024-10-03 01:14:30 字数 115 浏览 1 评论 0原文

如果数据存在一小时,我需要清除表中的所有记录。 为了知道开始时间,我有一列“StartTime”,数据类型为“date”。 我想我需要一个计时器来做到这一点,

我该如何在 oracle 中做到这一点?

I need to clear all records in a table if the data exist for one hour.
to know the start time, I have a column "StartTime" with "date" data type.
I think I need a timer to do this,

how can I do this in oracle ?

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

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

发布评论

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

评论(4

你的笑 2024-10-10 01:14:30

根据您的具体要求,我可能会考虑使用视图仅在查询时显示有效行。这会让人觉得只有最后一小时的记录可用。这也意味着您不需要在创建行一小时后将其删除。

然后要删除行,我会考虑使用 DBMS_JOB 或 DBMS_SCHEDULER 来删除行,正如其他一些答案中所建议的那样。

请记住,仅仅因为您的要求是在一小时后清除表中的行,您可能实际上只需要删除对它们进行查询的能力,您可以使用视图来做到这一点。

Depending on what your exact requirements are, I would probably look at using a view to only show the valid rows when queried. This would make it seem like only the last one hour of records were available. This would also mean that you don't need to remove rows exactly an hour after they are created.

Then to remove the rows, I would look at using DBMS_JOB or DBMS_SCHEDULER to remove the rows as has been suggested in some of the other answers.

Remember that just because your requirement is to clear the rows from the table after an hour, you probably really only need to remove the ability to query on them, which you could do with a view.

海未深 2024-10-10 01:14:30

适用于什么版本的 Oracle?

对于版本v7.3.4到9i,使用DBMS_JOB来安排任务。 10g+,您想使用DBMS_SCHEDULER。我不清楚你想要/需要它运行多久......

For what version of Oracle?

For version v7.3.4 to 9i, use DBMS_JOB to schedule a task. 10g+, you want to use DBMS_SCHEDULER. It's not clear to me how often you want/need this to run...

五里雾 2024-10-10 01:14:30

您可以在 Oracle 10G 及更高版本中使用 DBMS_SCHEDULER 创建计划作业。

如果您非常挑剔,您可以安排此作业(调用您的过程)每 1 分钟运行一次,以便在第 60 分钟到期时立即清除数据。

有关如何设置/的示例,请参阅此链接在 Oracle 10G 中通过脚本安排作业

You can create scheduled Jobs in Oracle 10G and above using the DBMS_SCHEDULER

If you are really fastidious, you can schedule this job - which calls your procedure - to run every 1 minute so that the data is cleared out as soon as the 60th minute expires.

Refer this link for an example of how to setup / schedule a job via scripts in Oracle 10G

心奴独伤 2024-10-10 01:14:30

要求不是很明确。

这是一个您必须运行一次并会删除存在超过一个小时的记录的作业/程序吗?如果是这种情况,您可以使用..

delete from <table_name>
where StartTime < (sysdate-1/24);
commit;

如果您需要不断清除记录,则需要将其安排为一项作业。频率取决于您希望删除记录的频率。

您想要解决的业务案例是什么?

The requirements are not Quite clear.

Is this a job/program that you have to run once and will delete records that existed for more than an hour? If that is the case, you can use..

delete from <table_name>
where StartTime < (sysdate-1/24);
commit;

If you need to purge records constantly, you'll need to schedule this as a job . The frequency will depend on how often you want the records to be deleted.

What is the business case you are trying to solve?

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