0% found this document useful (0 votes)
56 views19 pages

Create Materialized View: Purpose

1. CREATE MATERIALIZED VIEW is used to create a materialized view, which contains the results of a query and allows those results to be maintained on the local database. 2. Materialized views are useful for data warehousing and replication purposes. For replication, they allow copying of remote data locally. For data warehousing, they support query optimization. 3. The physical properties, storage characteristics, columns, partitioning, and refresh properties of a materialized view can be specified during creation.

Uploaded by

Ziad Baloch
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views19 pages

Create Materialized View: Purpose

1. CREATE MATERIALIZED VIEW is used to create a materialized view, which contains the results of a query and allows those results to be maintained on the local database. 2. Materialized views are useful for data warehousing and replication purposes. For replication, they allow copying of remote data locally. For data warehousing, they support query optimization. 3. The physical properties, storage characteristics, columns, partitioning, and refresh properties of a materialized view can be specified during creation.

Uploaded by

Ziad Baloch
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

CREATEMATERIALIZEDVIEW

Purpose
Usethe CREATE MATERIALIZED VIEWstatementtocreatea materializedview.A materializedviewisadatabaseobjectthatcontainstheresultsofaquery.The FROM clauseofthequerycannametables,views,andothermaterializedviews. Collectivelytheseobjectsarecalled mastertables(areplicationterm)or detail tables(adatawarehousingterm).Thisreferenceuses"mastertables"for consistency.Thedatabasescontainingthemastertablesarecalledthe master databases.
Note: Thekeyword SNAPSHOTissupportedinplaceof MATERIALIZED VIEWforbackwardcompatibility.

For replication purposes, materialized views allow you to maintain copies of remote dataonyourlocalnode.ThecopiescanbeupdatablewiththeAdvanced Replicationfeatureandareread-onlywithoutthisfeature.Youcanselectdatafrom a materialized view as you would from a table or view. In replication environments, thematerializedviewscommonlycreatedare primarykey, rowid, object,and subquerymaterializedviews.
SeeAlso: OracleDatabaseAdvancedReplicationforinformationon

thetypesofmaterializedviewsusedtosupportreplication Fordatawarehousingpurposes,thematerializedviewscommonlycreatedare materializedaggregateviews, single-tablematerializedaggregateviews,and materialized join views. All three types of materialized views can be used by query rewrite,anoptimizationtechniquethattransformsauserrequestwritteninterms ofmastertablesintoasemanticallyequivalentrequestthatincludesoneormore materializedviews.
SeeAlso:

ALTERMATERIALIZEDVIEWonpage 11-2 OracleDataWarehousingGuideforinformationonthetypesof materializedviewsusedtosupportdatawarehousing

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-5

materializedview.OracleDatabaseusestheseobjectstomaintainthematerialized viewdata.Youmusthavetheprivilegesnecessarytocreatetheseobjects.
SeeAlso:

CREATETABLEonpage 16-7, CREATEVIEWonpage 17-40,and CREATEINDEXonpage 14-75forinformationontheseprivileges OracleDatabaseAdvancedReplicationforinformationaboutthe prerequisitesthatapplytocreatingreplicationmaterializedviews OracleDataWarehousingGuideforinformationabouttheprerequisites thatapplytocreatingdatawarehousingmaterializedviews

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-7

physical_properties::=

(segment_attributes_clause::=onpage 15-11, table_compression::=onpage 15-12, index_ org_table_clause::=onpage 15-10) materialized_view_props::=


(column_properties::=onpage 15-12, table_partitioning_clauses::=onpage 16-19part of CREATE TABLEsyntax, parallel_clause::=onpage 15-15, build_clause::=on page 15-15) scoped_table_ref_constraint::=

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-9

create_mv_refresh::=

segment_attributes_clause::=

(physical_attributes_clause::=onpage 15-12, logging_clause::=onpage 15-12)

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-11

object_type_col_properties::=

(substitutable_column_clause::=onpage 15-13) substitutable_column_clause::=


nested_table_col_properties::=

(substitutable_column_clause::=onpage 15-13, object_properties::=onpage 16-11, physical_properties::=onpage 16-12partof CREATE TABLEsyntax, column_ properties::=onpage 15-12) varray_col_properties::=

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-13

LOB_partition_storage::=

(LOB_storage_clause::=onpage 15-14, varray_col_properties::=onpage 15-13) parallel_clause::=


build_clause::=

Semantics
schema
Specifytheschematocontainthematerializedview.Ifyouomit schema,then OracleDatabasecreatesthematerializedviewinyourschema.

materialized_view
Specifythenameofthematerializedviewtobecreated.OracleDatabasegenerates names for the table and indexes used to maintain the materialized view by adding a prexorsufxtothematerializedviewname.

OFobject_type
The OF object_typeclauseletsyouexplicitlycreatean objectmaterializedview oftype object_type.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-15

Ifyouspecifythisclause,thenyoucannotspecifya NOT NULLconstraintfor anycolumnthatisnotreferencedin subqueryunlessyoualsospecifya defaultvalueforthatcolumn.


SeeAlso: "CreatingPrebuiltMaterializedViews:Example"on

page 15-29

physical_properties_clause
The components of the physical_properties_clause have the same semantics formaterializedviewsthattheyhavefortables,withexceptionsandadditions describedinthesectionsthatfollow.
Restrictiononthe physical_properties_clause Youcannotspecify

ORGANIZATION EXTERNALforamaterializedview. segment_attributes_clause Usethe segment_attributes_clausetoestablishvaluesforthe PCTFREE, PCTUSED,and INITRANSparameters,thestoragecharacteristicsforthe materialized view, to assign a tablespace, and to specify whether logging is to occur. Inthe USING INDEXclause,youcannotspecify PCTFREEor PCTUSED.
TABLESPACEClause Specifythetablespaceinwhichthematerializedviewisto becreated.Ifyouomitthisclause,thenOracleDatabasecreatesthematerialized viewinthedefaulttablespaceoftheschemacontainingthematerializedview. SeeAlso: physical_attributes_clause on page 8-54 and storage_clause

onpage 8-57foracompletedescriptionoftheseclauses,including defaultvalues Specify LOGGINGor NOLOGGINGtoestablishthelogging characteristicsforthematerializedview.Thedefaultistheloggingcharacteristicof thetablespaceinwhichthematerializedviewresides.


logging_clause SeeAlso: logging_clauseonpage 8-47forafulldescriptionofthis

clause table_compression Usethe table_compressionclausetoinstructthedatabasewhethertocompress datasegmentstoreducediskandmemoryuse.The COMPRESSkeywordenables tablecompression.The NOCOMPRESSkeyworddisablestablecompression.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-17

materialized_view_props
Usethesepropertyclausestodescribeamaterializedviewthatisnotbasedonan existingtable.Tocreateamaterializedviewthatisbasedonanexistingtable,use the ON PREBUILT TABLEclause. column_properties The column_propertiesclauseletsyouspecifythestoragecharacteristicsofa LOB,nestedtable,varray,or XMLTypecolumn.The object_type_col_ propertiesarenotrelevantforamaterializedview.
SeeAlso: CREATETABLEonpage 16-7 fordetailedinformation aboutspecifyingtheparametersofthisclause

table_partitioning_clauses The table_partitioning_clauses let you specify that the materialized view is partitionedonspeciedrangesofvaluesoronahashfunction.Partitioningof materializedviewsisthesameaspartitioningoftables.
SeeAlso: table_partitioning_clausesonpage 16-48inthe CREATE

TABLEdocumentation CACHE|NOCACHE Fordatathatwillbeaccessedfrequently, CACHEspeciesthattheblocksretrieved forthistableareplacedatthemostrecentlyusedendoftheleastrecentlyused (LRU)listinthebuffercachewhenafulltablescanisperformed.Thisattributeis usefulforsmalllookuptables. NOCACHEspeciesthattheblocksareplacedatthe leastrecentlyusedendoftheLRUlist.


Note: NOCACHE has no effect on materialized views for which you specify KEEPinthe storage_clause.

SeeAlso: CREATETABLEonpage 16-7 forinformationabout

specifying CACHEor NOCACHE parallel_clause The parallel_clauseletsyouindicatewhetherparalleloperationswillbe supportedforthematerializedviewandsetsthedefaultdegreeofparallelismfor queriesandDMLonthematerializedviewaftercreation.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-19

Note: Thisclauseonlysetsthedefaultrefreshoptions.For instructionsonactuallyimplementingtherefresh,referto Oracle DatabaseAdvancedReplicationand OracleDataWarehousingGuide.

SeeAlso:

"PeriodicRefreshofMaterializedViews:Example"on page 15-30and "AutomaticRefreshTimesforMaterialized Views:Example"onpage 15-31 PL/SQLPackagesandTypesReferenceformoreinformationon refreshmethods

FASTClause Specify FASTtoindicatetheincrementalrefreshmethod,whichperformsthe refreshaccordingtothechangesthathaveoccurredtothemastertables.The changesforconventionalDMLchangesarestoredinthematerializedviewlog associatedwiththemastertable.Thechangesfordirect-path INSERToperationsare storedinthedirectloaderlog. Ifyouspecify REFRESH FAST,thenthe CREATEstatementwillfailunless materializedviewlogsalreadyexistforthematerializedviewmastertables.Oracle Databasecreatesthedirectloaderlogautomaticallywhenadirect-path INSERT takesplace.Nouserinterventionisneeded. ForbothconventionalDMLchangesandfordirect-path INSERToperations,other conditionsmayrestricttheeligibilityofamaterializedviewforfastrefresh. Materializedviewsarenoteligibleforfastrefreshifthedeningquerycontainsan analyticfunction.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-21

SeeAlso:

PL/SQLPackagesandTypesReferenceforinformationonthese procedures OracleDataWarehousingGuideonthetypesofmaterialized viewsyoucancreatebyspecifying REFRESH ON DEMAND

Ifyouspecify ON COMMITor ON DEMAND,thenyoucannotalsospecify START WITH or NEXT. STARTWITHClause Specifyadatetimeexpressionfortherstautomaticrefreshtime. NEXTClause Specifyadatetimeexpressionforcalculatingtheintervalbetweenautomatic refreshes. Boththe START WITHand NEXTvaluesmustevaluatetoatimeinthefuture.Ifyou omitthe START WITHvalue,thenthedatabasedeterminestherstautomatic refreshtimebyevaluatingthe NEXTexpressionwithrespecttothecreationtimeof thematerializedview.Ifyouspecifya START WITHvaluebutomitthe NEXTvalue, thenthedatabaserefreshesthematerializedviewonlyonce.Ifyouomitboththe START WITHand NEXTvalues,orifyouomitthe create_mv_refreshentirely, thenthedatabasedoesnotautomaticallyrefreshthematerializedview. WITHPRIMARYKEYClause Specify WITHPRIMARY KEYtocreateaprimarykeymaterializedview.Thisisthe defaultandshouldbeusedinallcasesexceptthosedescribedfor WITH ROWID. Primarykeymaterializedviewsallowmaterializedviewmastertablestobe reorganized without affecting the eligibility of the materialized view for fast refresh. Themastertablemustcontainanenabledprimarykeyconstraint.
RestrictiononPrimaryKeyMaterializedViews Youcannotspecifythisclausefor

an object materialized view. Oracle Database implicitly refreshes object materialized WITH OBJECT ID.
SeeAlso: OracleDatabaseAdvancedReplicationfordetailed

informationaboutprimarykeymaterializedviewsand "Creating PrimaryKeyMaterializedViews:Example"onpage 15-30

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-23

MASTER MASTERspeciestheremoterollbacksegmenttobeusedattheremote mastersitefortheindividualmaterializedview. LOCAL

LOCALspeciestheremoterollbacksegmenttobeusedforthelocal refreshgroupthatcontainsthematerializedview.Thisisthedefault.
SeeAlso: OracleDatabaseAdvancedReplicationforinformationon

specifyingthelocalmaterializedviewrollbacksegmentusingthe DBMS_REFRESHpackage Ifyouomit rollback_segment,thenthedatabaseautomaticallychoosesthe rollbacksegmenttobeused.Onemasterrollbacksegmentisstoredforeach materialized view and is validated during materialized view creation and refresh. If thematerializedviewiscomplex,thenthedatabaseignoresanymasterrollback segmentyouspecify. USING...CONSTRAINTSClause The USING... CONSTRAINTSclauseletsOracleDatabasechoosemorerewrite optionsduringtherefreshoperation,resultinginmoreefcientrefreshexecution. TheclauseletsOracleDatabaseuseunenforcedconstraints,suchasdimension relationshipsorconstraintsinthe RELYstate,ratherthanrelyingonlyonenforced constraintsduringtherefreshoperation.
Caution: The USING TRUSTED CONSTRAINTSclauseletsOracle Databaseusedimensionandconstraintinformationthathasbeen declared trustworthy by the database administrator but that has not beenvalidatedbythedatabase.Ifthedimensionandconstraint informationisvalid,thenperformancemayimprove.However,if thisinformationisinvalid,thentherefreshproceduremaycorrupt thematerializedvieweventhoughitreturnsasuccessstatus.

Ifyouomitthisclause,thenthedefaultis USING ENFORCED CONSTRAINTS. NEVERREFRESHClause Specify NEVER REFRESHtopreventthematerializedviewfrombeingrefreshed withanyOracleDatabaserefreshmechanismorpackagedprocedure.Oracle Databasewillignoreany REFRESHstatementonthematerializedviewissuedfrom suchaprocedure.Toreversethisclause,youmustissuean ALTER MATERIALIZED VIEW... REFRESHstatement.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-25

SeeAlso:

OracleDataWarehousingGuideformoreinformationonquery rewrite PL/SQLPackagesandTypesReferenceforinformationaboutthe DBMS_STATSpackage The EXPLAIN_MVIEWprocedureofthe DBMS_MVIEWpackage forhelpdiagnosingproblemswithqueryrewriteandthe TUNE_MVIEWprocedureofthe DBMS_MVIEWpackage correctionofqueryrewriteproblems CREATEFUNCTIONonpage 14-61

Specify DISABLEtoindicatethatthematerializedviewisnot eligibleforusebyqueryrewrite.Adisabledmaterializedviewcanberefreshed.


DISABLEClause

AS subquery
Specifythedeningqueryofthematerializedview.Whenyoucreatethe materializedview,OracleDatabaseexecutesthissubqueryandplacestheresultsin thematerializedview.ThissubqueryisanyvalidSQLsubquery.However,notall subqueriesarefastrefreshable,norareallsubquerieseligibleforqueryrewrite.
NotesontheDeningQueryofaMaterializedView

Oracle Database does not execute the dening query immediately if you specify BUILD DEFERRED. Oraclerecommendsthatyouqualifyeachtableandviewinthe FROMclauseof thedeningqueryofthematerializedviewwiththeschemacontainingit.
SeeAlso: ASsubqueryonpage 16-61inthe CREATE TABLE

documentationforsomeadditionalcaveats
RestrictionsontheDeningQueryofaMaterializedView

Thedeningqueryofamaterializedviewcanselectfromtables,views,or materializedviewsownedbytheuser SYS,butyoucannotenable QUERY REWRITEonsuchamaterializedview. Youcannotdeneamaterializedviewwithasubqueryintheselectlistofthe deningquery.Youcan,however,includesubquerieselsewhereinthedening query,suchasinthe WHEREclause.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-27

logcreatedin "CreatingaMaterializedViewLog:Examples"onpage 15-40,aswell asthetwoadditionallogsshownhere:


CREATEMATERIALIZEDVIEWLOGONtimes WITHROWID,SEQUENCE(time_id,calendar_year) INCLUDINGNEWVALUES; CREATEMATERIALIZEDVIEWLOGONproducts WITHROWID,SEQUENCE(prod_id) INCLUDINGNEWVALUES; CREATEMATERIALIZEDVIEWsales_mv BUILDIMMEDIATE REFRESHFASTONCOMMIT ASSELECTt.calendar_year,p.prod_id, SUM(s.amount_sold)ASsum_sales FROMtimest,productsp,saless WHEREt.time_id=s.time_idANDp.prod_id=s.prod_id GROUPBYt.calendar_year,p.prod_id;

CreatingMaterializedJoinViews:Example Thefollowingstatementcreatesand populatesthematerializedaggregateview sales_by_month_by_stateusing tablesinthesample shschema.Thematerializedviewwillbepopulatedwithdata assoonasthestatementexecutessuccessfully.Bydefault,subsequentrefresheswill beaccomplishedbyreexecutingthedeningqueryofthematerializedview:


CREATEMATERIALIZEDVIEWsales_by_month_by_state TABLESPACEexample PARALLEL4 BUILDIMMEDIATE REFRESHCOMPLETE ENABLEQUERYREWRITE ASSELECTt.calendar_month_desc,c.cust_state_province, SUM(s.amount_sold)ASsum_sales FROMtimest,saless,customersc WHEREs.time_id=t.time_idANDs.cust_id=c.cust_id GROUPBYt.calendar_month_desc,c.cust_state_province;

CreatingPrebuiltMaterializedViews:Example Thefollowingstatementcreatesa materializedaggregateviewforthepreexistingsummarytable, sales_sum_ table:


CREATETABLEsales_sum_table (monthVARCHAR2(8),stateVARCHAR2(40),salesNUMBER(10,2));

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-29

CREATEMATERIALIZEDVIEWLOGONemployees WITHPRIMARYKEY INCLUDINGNEWVALUES; CREATEMATERIALIZEDVIEWemp_data PCTFREE5PCTUSED60 TABLESPACEexample STORAGE(INITIAL50KNEXT50K) REFRESHFASTNEXTsysdate+7 ASSELECT*FROMemployees;

Thestatementdoesnotincludea START WITHparameter,soOracleDatabase determinestherstautomaticrefreshtimebyevaluatingthe NEXTvalueusingthe current SYSDATE.Amaterializedviewlogwascreatedfortheemployeetable,so OracleDatabaseperformsafastrefreshofthematerializedviewevery7days, beginning7daysafterthematerializedviewiscreated. Becausethematerializedviewconformstotheconditionsforfastrefresh,the databasewillperformafastrefresh.Theprecedingstatementalsoestablishes storagecharacteristicsthatthedatabaseusestomaintainthematerializedview.
AutomaticRefreshTimesforMaterializedViews:Example Thefollowing

statementcreatesthecomplexmaterializedview all_customersthatqueriesthe employeetablesonthe remoteand localdatabases:


CREATEMATERIALIZEDVIEWall_customers PCTFREE5PCTUSED60 TABLESPACEexample STORAGE(INITIAL50KNEXT50K) USINGINDEXSTORAGE(INITIAL25KNEXT25K) REFRESHSTARTWITHROUND(SYSDATE+1)+11/24 NEXTNEXT_DAY(TRUNC(SYSDATE),'MONDAY')+15/24 ASSELECT*FROMsh.customers@remote UNION SELECT*FROMsh.customers@local;

OracleDatabaseautomaticallyrefreshesthismaterializedviewtomorrowat11:00 a.m.andsubsequentlyeveryMondayat3:00p.m.Thedefaultrefreshmethodis FORCE. The deningquerycontainsa UNIONoperator,whichisnotsupportedfor fastrefresh,sothedatabasewillautomaticallyperformacompleterefresh. Theprecedingstatementalsoestablishesstoragecharacteristicsforboththe materializedviewandtheindexthatthedatabaseusestomaintainit:

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-31

CREATEMATERIALIZEDVIEWLOG
Purpose
Use the CREATE MATERIALIZED VIEW LOG statement to create a materialized view log,whichisatableassociatedwiththemastertableofamaterializedview.
Note: Thekeyword SNAPSHOTissupportedinplaceof MATERIALIZED VIEWforbackwardcompatibility.

WhenDMLchangesaremadetomastertabledata,OracleDatabasestoresrows describingthosechangesinthematerializedviewlogandthenusesthe materializedviewlogtorefreshmaterializedviewsbasedonthemastertable.This processiscalledincrementalor fastrefresh.Withoutamaterializedviewlog, OracleDatabasemustreexecutethematerializedviewquerytorefreshthe materializedview.Thisprocessiscalleda completerefresh.Usually,afastrefresh takeslesstimethanacompleterefresh. Amaterializedviewlogislocatedinthemasterdatabaseinthesameschemaasthe mastertable.Amastertablecanhaveonlyonematerializedviewlogdenedonit. OracleDatabasecanusethismaterializedviewlogtoperformfastrefreshesforall fast-refreshablematerializedviewsbasedonthemastertable. Tofastrefreshamaterializedjoinview,youmustcreateamaterializedviewlogfor eachofthetablesreferencedbythematerializedview.
SeeAlso:

CREATEMATERIALIZEDVIEWonpage 15-5, ALTER MATERIALIZEDVIEWonpage 11-2, OracleDatabaseConcepts, OracleDataWarehousingGuide,and OracleDatabaseAdvanced Replicationforinformationonmaterializedviewsingeneral ALTERMATERIALIZEDVIEWLOGonpage 11-21for informationonmodifyingamaterializedviewlog DROPMATERIALIZEDVIEWLOGonpage 17-90for informationondroppingamaterializedviewlog OracleDatabaseConceptsand OracleDatabaseUtilitiesfor informationonusingdirectloaderlogs

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-33

Syntax
create_materialized_vw_log::=

(physical_attributes_clause::=onpage 15-12, logging_clause::=onpage 15-36, parallel_ clause::=onpage 15-36, table_partitioning_clauses::=onpage 16-19(in CREATE TABLE), new_values_clause::=onpage 15-36)

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-35

table
Specifythenameofthemastertableforwhichthematerializedviewlogistobe created.
RestrictiononMasterTablesofMaterializedViewLogs Youcannotcreatea

materializedviewlogforatemporarytableorforaview.
SeeAlso: "CreatingaMaterializedViewLog:Examples"on

page 15-40

physical_attributes_clause
Usethe physical_attributes_clausetodenephysicalandstorage characteristicsforthematerializedviewlog.
SeeAlso: physical_attributes_clause on page 8-54 and storage_clause

onpage 8-57foracompletedescriptiontheseclauses,including defaultvalues

TABLESPACEClause
Specifythetablespaceinwhichthematerializedviewlogistobecreated.Ifyou omitthisclause,thenthedatabasecreatesthematerializedviewloginthedefault tablespaceoftheschemaofthematerializedviewlog.

logging_clause
Specifyeither LOGGINGor NOLOGGINGtoestablishtheloggingcharacteristicsfor thematerializedviewlog.Thedefaultistheloggingcharacteristicofthetablespace inwhichthematerializedviewlogresides.
SeeAlso: logging_clauseonpage 8-47forafulldescriptionofthis

clause

CACHE|NOCACHE
Fordatathatwillbeaccessedfrequently, CACHEspeciesthattheblocksretrieved forthislogareplacedatthemostrecentlyusedendoftheleastrecentlyused(LRU) listinthebuffercachewhenafulltablescanisperformed.Thisattributeisuseful forsmalllookuptables. NOCACHEspeciesthattheblocksareplacedattheleastrecentlyusedendofthe LRUlist.Thedefaultis NOCACHE.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-37

OBJECTID Specify OBJECT IDtoindicatethatthesystem-generatedor

user-denedobjectidentierofeverymodiedrowshouldberecordedinthe materializedviewlog.
RestrictiononOBJECTID Youcanspecify OBJECT IDonlywhencreatingalog

onanobjecttable,andyoucannotspecifyitforstoragetables.
PRIMARYKEY Specify PRIMARY KEYtoindicatethattheprimarykeyofallrows

changedshouldberecordedinthematerializedviewlog.
ROWID Specify ROWIDtoindicatethattherowidofallrowschangedshouldbe recordedinthematerializedviewlog. SEQUENCE Specify SEQUENCEtoindicatethatasequencevalueproviding additionalorderinginformationshouldberecordedinthematerializedviewlog. Sequencenumbersarenecessarytosupportfastrefreshaftersomeupdate scenarios. SeeAlso: OracleDataWarehousingGuideformoreinformationon

theuseofsequencenumbersinmaterializedviewlogsandfor examplesthatusethisclause
column Specifythecolumnswhosevaluesyouwanttoberecordedinthe

materializedviewlogforallrowsthatarechanged.Typicallythesecolumnsare ltercolumnsandjoincolumns.
RestrictionsontheWITHClause

Youcanspecifyonlyone PRIMARY KEY,one ROWID,one OBJECT ID,one SEQUENCE,andonecolumnlistforeachmaterializedviewlog. Primarykeycolumnsareimplicitlyrecordedinthematerializedviewlog. Therefore,youcannotspecifyeitherofthefollowingcombinationsif column containsoneoftheprimarykeycolumns:
WITH...PRIMARYKEY...(column) WITH...(column)...PRIMARYKEY WITH(column)

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-39

withthe ROWIDclause,whichenablesfastrefreshformoretypesofmaterialized views:


CREATEMATERIALIZEDVIEWLOGONcustomersWITHPRIMARYKEY,ROWID;

Thismaterializedviewlogmakesfastrefreshpossibleforrowidmaterializedviews andformaterializedjoinviews.Toprovideforfastrefreshofmaterialized aggregateviews,youmustalsospecifythe SEQUENCEand INCLUDING NEW VALUESclauses,asshowninthenextstatement.


SpecifyingFilterColumnsforMaterializedViewLogs:Example Thefollowing statementcreatesamaterializedviewlogonthe sh.salestableandisusedin "CreatingMaterializedAggregateViews:Example"onpage 15-28.Itspeciesas ltercolumnsallofthecolumnsofthetablereferencedinthatmaterializedview.
CREATEMATERIALIZEDVIEWLOGONsales WITHROWID,SEQUENCE(amount_sold,time_id,prod_id) INCLUDNGNEWVALUES;

SpecifyingJoinColumnsforMaterializedViewLogs:Example Thefollowing statementcreatesamaterializedviewlogonthe order_itemstableofthesample oeschema.Thelogrecordsprimarykeysand product_id,whichisusedasajoin columnin "CreatingaFastRefreshableMaterializedView:Example"onpage 15-32.


CREATEMATERIALIZEDVIEWLOGONorder_itemsWITH(product_id);

IncludingNewValuesinMaterializedViewLogs:Example The following example

createsamaterializedviewlogonthe oe.product_informationtablethat species INCLUDING NEW VALUES:


CREATEMATERIALIZEDVIEWLOGONproduct_information WITHROWID,SEQUENCE(list_price,min_price,category_id) INCLUDINGNEWVALUES;

Youcouldcreatethefollowingmaterializedaggregateviewtousethe product_ informationlog:


CREATEMATERIALIZEDVIEWproducts_mv REFRESHFASTONCOMMIT ASSELECTSUM(list_price-min_price),category_id FROMproduct_information GROUPBYcategory_id;

Thismaterializedviewiseligibleforfastrefreshbecausethelogdenedonits mastertableincludesbotholdandnewvalues.

SQLStatements:CREATELIBRARYtoCREATESPFILE

15-41

You might also like