oracle 物化视图:如何在表数据更改时自动刷新它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25366926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:28:34  来源:igfitidea点击:

Materialized View: How to automatically refresh it upon table data changes?

sqloracleviewsoracle-sqldevelopermaterialized-views

提问by Jemru

Is there a way in Oracle Materialized views so that it automatically refresh itself when there are changes on the tables used in the materialized view? What is the Refresh Mode and Refresh Method that I should use? What options should I use using Sql Developer?

Oracle 物化视图中是否有一种方法可以使其在物化视图中使用的表发生更改时自动刷新?我应该使用什么刷新模式和刷新方法?我应该使用 Sql Developer 使用哪些选项?

Thank you in advance

先感谢您

回答by Wernfried Domscheit

Yes, you can define a Materialized View with ON COMMIT, e.g.:

是的,您可以使用 定义物化视图ON COMMIT,例如:

CREATE MATERIALIZED VIEW sales_mv
   BUILD IMMEDIATE
   REFRESH FAST ON COMMIT
   AS SELECT t.calendar_year, p.prod_id ... FROM ...

In this case after every commit the MV is refreshed, provided the last transaction was done on master table, of course. Since refresh is done after each commit it is strongly recommendd to use FAST REFRESH, rather than COMPLETEthis would last too long.

在这种情况下,每次提交后,MV 都会刷新,当然,前提是最后一个事务是在主表上完成的。由于刷新是在每次提交后完成的,因此强烈建议使用FAST REFRESH,而不是COMPLETE这会持续太久。

You have several restrictions and pre-conditions in order to use FAST REFRESH, check Oracle documentation: CREATE MATERIALIZED VIEW, FAST Clausefor details.

为了使用FAST REFRESH,您有几个限制和先决条件,请查看 Oracle 文档:CREATE MATERIALIZED VIEW,FAST Clause了解详细信息。

回答by Daniel Stolf

I don't think there's any way to 'automatically' replicate the changes to the m.view right after they are made. But there are ways to use FAST (incremental) refresh on demand, you'd only have to schedule a job for the m.view or and m.view group to do the refresh. You can also use m.view log to keep track of all the dml and the have it propagated to the m.view with a fast refresh on a remote database through the db link.

我认为没有任何方法可以在更改完成后立即“自动”将更改复制到 m.view。但是有一些方法可以按需使用 FAST(增量)刷新,您只需为 m.view 或 m.view 组安排一个作业来进行刷新。您还可以使用 m.view 日志来跟踪所有 dml 并将其传播到 m.view,并通过 db 链接快速刷新远程数据库。

If you need the changes to be replicated as soon as they are made, then I recommend using golden gate or streams (if you don't want do license GG). Just beware that oracle discontinued support for streams in favor of Golden Gate, so if you have any issues, you're on your own. But anyway, it's a pretty solid replication tool, once you get the hang of it.

如果您需要在更改完成后立即复制它们,那么我建议使用金门或流(如果您不想做许可证 GG)。请注意,oracle 停止了对流的支持,转而支持 Golden Gate,因此如果您有任何问题,请自行解决。但无论如何,一旦掌握了它,它就是一个非常可靠的复制工具。