您好,登錄后才能下訂單哦!
1、創建物化視圖
TEST8@ odb>create materialized view v_wuhua as select * from gaoshuiwei;
create materialized view v_001 asselect * from gaoshuiwei
*
ERROR at line 1:
ORA-01031: insufficient privileges
sys@ odb>grant create materialized view to test8;
TEST8@ odb>create materializedview v_wuhua as select * from gaoshuiwei;
Materialized view created.
TEST8@ odb>create view v_shituas select * from gaoshuiwei;
create view v_shitu as select *from gaoshuiwei
*
ERROR at line 1:
ORA-01031: insufficient privileges
sys@ odb>grant create view to test8;
TEST8@ odb>create view v_shituas select * from gaoshuiwei;
View created.
清空v_wuhua數據提示數據操作不合法,說明物化視圖只能讀不能刪除數據,
1、比較物化視圖和視圖的區別
TEST8@odb>delete from gaoshuiwei; //清空基表
68310rows deleted.
查詢物化視圖和普通視圖的區別
TEST8@odb>select count(*) from v_wuhua;
COUNT(*)
----------
68310
TEST8@odb>select count(*) from v_shitu;
COUNT(*)
----------
0
可以看到隨著基表的被清空,物化視圖是沒有變化的,而普通視圖隨之清空;重新插入數據效果還是一樣物化視圖不變,普通視圖隨著基表的變化而變化
TEST8@odb>insert into gaoshuiwei select * from all_objects;
68314rows created.
TEST8@odb>commit;
Commitcomplete.
TEST8@odb>select count(*) from gaoshuiwei;
COUNT(*)
----------
68314
TEST8@odb>select count(*) from v_wuhua;
COUNT(*)
----------
68310
TEST8@odb>select count(*) from v_shitu;
COUNT(*)
----------
68314
TEST8@odb>exec dbms_mview.refresh('V_WUHUA'); //刷新物化視圖數據這時和基表數據一致了。
物化視圖不僅可以全量的刷新數據還可以增量的刷新數據;
TEST8@odb>create materialized view v_wuhua1 as select * from gaoshuiwei whererownum<1;
Materializedview created.
TEST8@odb>select count(*) from v_wuhua1;
COUNT(*)
----------
0
selectdbms_metadata.get_ddl('MATERIALIZED_VIEW','V_WUHUA1','TEST8') FROM DUAL;
3、查詢重寫
TEST8@odb>create materialized view v_wuhua3 enable query rewrite as select * fromgaoshuiwei;
Materializedview created.
看一下基表的查詢執行計劃,執行計劃上看表面查詢的是基表實際上查詢的是物化視圖;
4、刪除物化視圖
DROPMATERIALIZED VIEW V_TESTMV;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。