暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 插入记录后删除记录

askTom 2017-06-29
496

问题描述

1) 我想使用触发器在插入10分钟后自动删除插入的记录。有可能吗?如果不可能,给可能的方式怎么办?

否则给另一种不同的方式来做这件事?

谢谢。

专家解答

你可以有工作去做,例如

SQL> create table t ( x int, deletion_time date );

Table created.

SQL> insert into t values (1, sysdate + 10/1440);

1 row created.

SQL> insert into t values (2, sysdate + 10/1440);

1 row created.

SQL> insert into t values (3, sysdate + 10/1440);

1 row created.

SQL> insert into t values (4, sysdate + 10/1440);

1 row created.

SQL> insert into t values (5, sysdate + 10/1440);

1 row created.

SQL> insert into t values (6, sysdate + 10/1440);

1 row created.

SQL>
SQL> select * from t;

         X DELETION_TIME
---------- -------------------
         1 30/06/2017 12:51:59
         2 30/06/2017 12:52:02
         3 30/06/2017 12:52:05
         4 30/06/2017 12:52:08
         5 30/06/2017 12:52:11
         6 30/06/2017 12:52:14

6 rows selected.

SQL> create or replace
  2  procedure del_old_rows is
  3  begin
  4    delete from t where deletion_time < sysdate ;
  5    commit;
  6  end;
  7  /

Procedure created.

SQL>
SQL> declare
  2    j int;
  3  begin
  4    dbms_job.submit(j,'del_old_rows;',sysdate,'sysdate+1/1440');
  5  end;
  6  /

PL/SQL procedure successfully completed.
复制


一旦我提交,该作业将变为活动状态,并且每分钟作业将运行并删除已超过其到期时间的任何行。


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论