如何从超过200天的tablea中清除数据

时间:2018-09-10 12:25:17

标签: sql oracle purge

我是数据库新手。我想从表中清除一些数据(即清除早于200天的旧数据),因此我得到了一个Sql脚本。有人可以帮我如何运行脚本@purge.sql "no of days"

SQL>@@purge.sql 200

实际上,我的目的是索取磁盘空间服务器。清除后,我们需要执行任何步骤来声明文件系统。

CREATE OR REPLACE PROCEDURE TEST_PURGE_REC 
(
  DAYS IN VARCHAR2 /* Number of days as an parameter*/

) AS 
BEGIN
/* This deletes the records from the tables TRACK_DETAILS,LOG_DETAILS  tables of TEST schema*/

  DELETE FROM TRACK_DETAILS WHERE TO_CHAR(CREATION_TIME,'DD-MON-YY') < TO_DATE(SYSDATE -DAYS);
  DELETE FROM LOG_DETAILS WHERE TO_CHAR(CREATION_TIME,'DD-MON-YY') < TO_DATE(SYSDATE -DAYS);
  COMMIT;
  DBMS_OUTPUT.PUT_LINE('The records are deleted successfully');

END TEST_PURGE_REC

1 个答案:

答案 0 :(得分:1)

我认为您必须更改它的mssql格式,因为您的查询符合oracle标准

   DELETE FROM TRACK_DETAILS 
   WHERE convert(date,CREATION_TIME) < dateadd(day,-200,getdate());

    go

   DELETE FROM LOG_DETAILS
   WHERE convert(date,CREATION_TIME) < dateadd(day,-200,getdate());