oracle中删除一天记录吗,删除oracle SQL中超过24小时的记录(delete records older than 24 hours in oracle SQL)...

删除oracle SQL中超过24小时的记录(delete records older than 24 hours in oracle SQL)

我想删除所有超过24小时的记录。 我使用以下查询相同,但有时不完美运行。 我想知道我的查询是对还是错? 或者哪种方法更好。

delete from TEMP_SERVICE_OPTION where EVENT_DATE < TRUNC(SYSDATE) - 1;

I want to delete all the records which is older than 24 hours. I am using the below query for the same but sometimes doesn't run perfectly. I want to know whether my query is right or wrong ? Or which is better way to do so.

delete from TEMP_SERVICE_OPTION where EVENT_DATE < TRUNC(SYSDATE) - 1;

原文:https://stackoverflow.com/questions/29097124

更新时间:2019-12-22 14:12

最满意答案

如果你想要超过24小时,那么:

where event_date < sysdate - 1

如果你想在昨天之前 ,那么做:

where event_date < trunc(sysdate) - 1

至于性能,这取决于有多少行被删除。 如果你的表只有成千上万行,那么这很好。 如果它有数百万行,那么您可能需要在event_date上有一个索引。 或者,您甚至可能想要采取不同的方法 - 将数据选择到临时表格中,截断原始表格,然后重新插入它。

If you want older than 24 hours then do:

where event_date < sysdate - 1

If you want before yesterday, then do:

where event_date < trunc(sysdate) - 1

As for performance, that depends on how many rows are being deleted. If your table only has thousands of rows, then this is fine. If it has millions of rows, then you might want an index on event_date. Or, you might even want to take a different approach -- selecting the data into a temporary table, truncating the original table, and then re-inserting it.

2015-03-17

相关问答

SELECT *

FROM table_name

WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)

SELECT *

FROM table_name

WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)

SELECT DISTINCT c.constit_id AS constitid,

REPLACE (c.in_labelname, 'None', '') AS fullname,

c.firstname AS firstname, c.lastname AS lastname,

c.indiv_title AS title, e.e_addr AS email,

'InAct

...

我不确定你的架构,但我会采用不同的方式。 我会有一个与验证链接对应的数据库记录的日期/时间。 单击链接时,请验证数据库记录的日期和时间是否在当前时间的24小时内。 如果是这样,请允许,否则拒绝它。 I'm not sure of your schema but I would do it a different way. I would have a date/time against the database record that corresponds to the validation l

...

对于OBIEE报告: timestampadd(SQL_TSI_DAY,-30,CURRENT_DATE)

(要么) SYSDATE, cast(EVALUATE('SYSDATE-30') as timestamp)

对于SQLPLUS,请尝试此操作 - SYSDATE将返回当前日期; 减去30天数: SELECT *

FROM TABLE

WHERE DATE_FIELD < SYSDATE-30;

参考文献: http://oracle.ittoolbox.com/grou

...

假设这是Oracle,那么: select name, count(name)

from table

where gmts > sysdate -1

or name = (select name from table where gmts > sysdate -2 and rownum <= 1)

group by name

order by gmts desc;

如果是MySQL使用限制: select name, count(name)

from table

...

通过执行以下操作,您可以获取datetime值: SELECT DATEADD(HOUR,6,CONVERT(DATETIME, CONVERT(DATE ,GETDATE()))) Today6AM,

DATEADD(HOUR,-18,CONVERT(DATETIME, CONVERT(DATE ,GETDATE()))) Yesterday6AM

通过这样做: CONVERT(DATE ,GETDATE())您将剥离今天日期的时间部分。 将它转换回datetime为您今天提供午

...

我能够通过使用dbenham的getTimestamp.bat解决问题: http : //www.dostips.com/forum/viewtopic.php? f = 3& t = 4847&p = 274222#p27422 这是我能找到的唯一能够计算昨天日期的工作批处理文件(可能是任何一天)。 它可能是唯一可用的,因为所有其他(以及所有关于StackOverflow线程的链接)都不考虑区域设置,因此它们甚至都没有为我启动。 call getTimeStamp -od -1 -f {dd}

...

SELECT * FROM stats WHERE STR_TO_DATE(timespan,"%W, %b %d %Y, %h:%i:%s %p") >= date_sub(now(), INTERVAL 1 DAY)

STR_TO_DATE会将您的字符串转换为日期格式(Ymd H:i:s)然后您可以将它与now()返回的日期进行比较 SELECT * FROM stats WHERE STR_TO_DATE(timespan,"%W, %b %d %Y, %h:%i:%s %p") >= d

...

如果你想要超过24小时,那么: where event_date < sysdate - 1

如果你想在昨天之前 ,那么做: where event_date < trunc(sysdate) - 1

至于性能,这取决于有多少行被删除。 如果你的表只有成千上万行,那么这很好。 如果它有数百万行,那么您可能需要在event_date上有一个索引。 或者,您甚至可能想要采取不同的方法 - 将数据选择到临时表格中,截断原始表格,然后重新插入它。 If you want older than 24 h

...

这比任何事情都更具信息性,或许也可以回答你的问题。 我正试图扩展我上面的长篇评论。 这就是我的工作。 这不是圣经和个人偏好的盛行。 在MySQL表中,创建一个INTEGER,甚至VARCHAR也可以。 使用PHP生成时间创建(1970年的一系列数字)。 生成如下: $currentTime = time(); // eg 1439823230 这在INSERT查询期间使用,前提是它们也是通过PHP发起的。 现在,您还可以考虑时区,但这又取决于您的偏好和/或服务器位置。 现在,当您的数据库中有大量项

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值