简体   繁体   English

使用oracle 11g的前一天数据

[英]Previous Day's data using oracle 11g

Currently I am fetching data for every 1 hour using this: 目前,我使用此方法每1小时获取一次数据:

create_date >= sysdate -1/24

When the process runs at midnight 12:00 am and the date changes to next day, is there anyway in Oracle to pick up data entered between 11pm to 12 am the previous day. 当该流程在午夜12:00运行并且日期更改为第二天时,Oracle中是否仍然可以提取在前一天的晚上11点至凌晨12点之间输入的数据。

Thanks 谢谢

如果您不在午夜运行SQL,则可以使用trunc函数执行以下操作:

 create_date between trunc(sysdate) - 1/24 and trunc(sysdate)

If you are running the process every hour, you will pick up the previous hour. 如果您每小时都在运行该过程,则将接听前一个小时。 For example, if you run at 12:10 AM, your clause will pick up everything from 11:10 PM of the previous day to 12:10 AM of the current day. 例如,如果您在12:10 AM运行,那么您的子句将处理从前一天的11:10 PM到当天的12:10 AM的所有内容。

If you have to be sure to pick up absolutely everything, I suggest that you change your logic. 如果您必须确保完全掌握所有内容,建议您更改逻辑。 If you don't, and your procedure doesn't run for some reason, such as the database is down for maintenance, you will miss processing some records 如果您不这样做,并且由于某种原因您的过程未运行(例如,由于维护数据库已关闭),您将无法处理某些记录

When your procedure starts, capture the current date/time and store it in a table. 过程开始时,捕获当前日期/时间并将其存储在表中。 When your procedure runs, fetch that date and use that last value as your start value: 当过程运行时,获取该日期并将其最后一个值用作起始值:

create_date between last_date and procedure_start_date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM