Oracle materialized views: 25/24 in REFRESH / NEXT parameter

yc0p9oo0  于 2022-12-11  发布在  Oracle
关注(0)|答案(2)|浏览(121)

I'm trying to figure out the meaning of 25/24 in this REFRESH parameter of an Oracle materialized view found on a repository:
REFRESH FORCE ON DEMAND START WITH sysdate+0 NEXT trunc(SYSDATE) + 25/24
I'm trying to find the correct refresh scheduling of this Oracle materialized view: 1/24 means "every one hour' but I'm not sure about the meaning of 25/24 and I couldn't find the correct answer so far...
Can anyone give an help? Thanks in advance.
Marco

3qpi33ja

3qpi33ja1#

That's tomorrow, 1 hour after midnight:

SQL> select sysdate right_now,
  2         trunc(SYSDATE) + 25/24 what_is_that
  3  from dual;

RIGHT_NOW           WHAT_IS_THAT
------------------- -------------------
06.12.2022 12:20:53 07.12.2022 01:00:00

SQL>

trunc "removes" time component from sysdate (sets it to midnight) and then adds 25 hours to it.

ccgok5k5

ccgok5k52#

来自CREATE MATERIALIZED VIEW文档
条款
指定用于计算自动刷新间隔的日期时间表达式。
START WITHNEXT值都必须计算为将来的某个时间。如果省略START WITH值,则数据库通过计算与实体化视图的创建时间相关的NEXT表达式来确定第一次自动刷新的时间。如果指定START WITH值但省略NEXT值,则数据库只会重新整理具体化视观表一次。如果您同时省略START WITHNEXT值,或完全省略create_mv_refresh,则数据库不会自动重新整理具体化视观表。
您的陈述:

REFRESH FORCE ON DEMAND START WITH sysdate+0 NEXT trunc(SYSDATE) + 25/24

实际上是每X小时刷新一次,其中X是现在的时间(SYSDATE + 0)与明天01:00的时间差(TRUNC(SYSDATE)给出今天的午夜,然后+25/24加上25小时)。因此,如果您在午夜执行CREATE MATERIALIZED VIEW语句,则它将每25小时刷新一次,如果您在上午9点执行它,则它将每16小时刷新一次,等等。
如果您希望每25小时运行一次,则可以删除TRUNC

REFRESH FORCE ON DEMAND START WITH SYSDATE NEXT SYSDATE + 25/24

或者,等效地,使用INTERVAL文字而不是算术:

REFRESH FORCE ON DEMAND START WITH SYSDATE NEXT SYSDATE + INTERVAL '25' HOUR

相关问题