Professional Documents
Culture Documents
MaterializedViews:ViewsvsMaterializedViews
SQLSnippets:TutorialsforOracleDevelopers
Search
CustomSearch
Miscellany
About
Home
MaterializedViews
SQLFeatures
Nightshade
Creations
MaterializedViews
Views
ViewsvsMaterializedViews
vs
Materialized
Likeitspredecessortheview,materializedviewsallowyoutostorethe
Views
definitionofaqueryinthedatabase.
REFRESH
COMPLETE
Materialized
View
Logs
Table
REFRESH
FAST
Purging
Materialized
View
Logs
select*fromT;
KEYVAL
1a
2b
EXPLAIN_MVIEW
3c
4
REFRESH
FORCE
REFRESH
FAST
Categories
customize
CafePress
View
MaterializedView
createviewv
as
select*
fromt;
creatematerializedviewmv
as
select*
fromt;
select*fromV;
select*fromMV;
KEYVAL
1a
2b
3c
4
KEYVAL
1a
2b
3c
4
NEVER
REFRESH
ON
DEMAND
Unlikeviews,however,materializedviewsalsostoretheresultsofthe
queryinthedatabase.Inthefollowingqueriesnotehowtherowid'sfor
ON
COMMIT thetableandtheviewareidentical,indicatingtheviewreturnstheexact
samedatastoredinthetable.Therowidsofthematerializedview,onthe
Constraints
otherhand,differfromthoseofthetable.Thisindicatesthematerialized
Indexes
viewisreturningaphysicallyseparatecopyofthetabledata.
ENABLE
QUERY
REWRITE
Query
Rewrite
Restrictions
and
Capabilities
Join
Queries
Aggregate
Queries
Nested
Materialized
Views
View
MaterializedView
selectrowid
fromT
orderbyrowid;
selectrowid
fromV
orderbyrowid;
selectrowid
fromMV
orderbyrowid;
ROWID
AAAgY9AAEAAAAVfAAA
AAAgY9AAEAAAAVfAAB
AAAgY9AAEAAAAVfAAC
AAAgY9AAEAAAAVfAAD
ROWID
AAAgY9AAEAAAAVfAAA
AAAgY9AAEAAAAVfAAB
AAAgY9AAEAAAAVfAAC
AAAgY9AAEAAAAVfAAD
ROWID
AAAgZFAAEAAADyEAAA
AAAgZFAAEAAADyEAAB
AAAgZFAAEAAADyEAAC
AAAgZFAAEAAADyEAAD
More
Info
Setup
Cleanup
<Previous
Table
Thedifferencebetweenviewsandmaterializedviewsbecomeseven
moreevidentthanthiswhentabledataisupdated.
Next>
Table
ReadUsingSQLSnippets
beforeusinganyofthissite's
samplecodeortechniqueson
yourownsystems.
View
MaterializedView
updatetsetval=upper(val);
select*fromT;
http://www.sqlsnippets.com/en/topic12874.html
select*fromV;
select*fromMV;
1/3
2/16/2016
MaterializedViews:ViewsvsMaterializedViews
KEYVAL
1A
2B
3C
4
KEYVAL
1A
2B
3C
4
KEYVAL
1a
2b
3c
4
Notehow,aftertheupdate,theviewdatamatchesthetabledatabutthe
materializedviewdatadoesnot.Datainmaterializedviewsmustbe
refreshedtokeepitsynchronizedwithitsbasetable.Refreshingcan
eitherbedonemanually,asbelow,orautomaticallybyOracleinsome
cases.
Table
View
MaterializedView
executedbms_mview.refresh('MV');
select*fromT;
select*fromV;
select*fromMV;
KEYVAL
1A
2B
3C
4
KEYVAL
1A
2B
3C
4
KEYVAL
1A
2B
3C
4
Nowthatthematerializedviewhasbeenrefresheditsdatamatchesthat
ofitsbasetable.
Cleanup
dropmaterializedviewmv;
dropviewv;
updatetsetval=lower(val);
commit;
< MaterializedViews
REFRESHCOMPLETE >
LinkingtoSQLSnippets
TolinktothispageinOracleTechnologyNetworkForumsorOraFAQ
Forumscutandpastethiscode.
[url=http://www.sqlsnippets.com/en/topic12874.html]SQLSnippets:
MaterializedViewsViewsvsMaterializedViews[/url]
TolinktothispageinHTMLdocumentsorBloggercommentscutandpastethis
code.
<ahref="http://www.sqlsnippets.com/en/topic12874.html">SQLSnippets:
MaterializedViewsViewsvsMaterializedViews</a>
Tolinktothispageinotherwebsitesusethefollowingvalues.
http://www.sqlsnippets.com/en/topic12874.html
2/3
2/16/2016
MaterializedViews:ViewsvsMaterializedViews
LinkText:SQLSnippets:MaterializedViewsViewsvsMaterializedViews
URL(href):http://www.sqlsnippets.com/en/topic12874.html
TermsandConditionsofUseDisclaimerPrivacyPolicy
ThispagewasfirstpublishedonMarch19,2008.
CopyrightJosephFuda20062011.Allrightsreserved.
TheviewsexpressedonthissitearemyownanddonotnecessarilyreflecttheviewsofOracle.
http://www.sqlsnippets.com/en/topic12874.html
3/3