我需要以不规则的间隔自动刷新物化视图,例如0800hrs,1200hrs 1800hrs和2200hrs。我只能定期安排刷新,如下所示
...
REFRESH FORCE ON DEMAND START WITH sysdate+0 NEXT sysdate+(6/24)
AS Select * from Employee;
答案 0 :(得分:3)
您可以在CASE
中添加NEXT
声明。所以你可以做类似
NEXT (CASE WHEN to_number( to_char( sysdate, 'HH24' )) >= 22
THEN trunc(sysdate+1) + interval '8' hour
...
ELSE null
END)
为了一般的理智,我通常会创建一个新函数(即get_next_refresh_time
)来实现这个CASE
语句,并在物化视图中引用该函数。
CREATE OR REPLACE FUNCTION get_next_refresh_time
RETURN DATE
IS
l_dt DATE;
BEGIN
SELECT CASE WHEN to_number( to_char( sysdate, 'HH24' )) >= 22
THEN trunc(sysdate+1) + interval '8' hour
WHEN to_number( to_char( sysdate, 'HH24' )) < 8
THEN trunc(sysdate) + interval '8' hour
WHEN to_number( to_char( sysdate, 'HH24' )) between 8 and 11
THEN trunc(sysdate) + interval '12' hour
WHEN to_number( to_char( sysdate, 'HH24' )) between 12 and 17
THEN trunc(sysdate) + interval '18' hour
WHEN to_number( to_char( sysdate, 'HH24' )) between 18 and 21
THEN trunc(sysdate) + interval '22' hour
ELSE null
END
INTO l_dt
FROM dual;
RETURN l_dt;
END;
NEXT get_next_refresh_time;
答案 1 :(得分:2)
我喜欢使用DBMS_SCHEDULER并设置一个作业来调用DBMS_MVIEW.REFRESH(参见http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_mview.htm#ARPLS027)。这也为您的刷新提供了更多选项。