Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
OER Unit 3 -Materialized view exercise solution
1. Data warehouse Design Using Oracle
https://www.oercommons.org/authoring/edit/21861
Dr. Girija Narasimhan 1
OER- UNIT 3 Materialized View
Exercise Solution
2. Dr. Girija Narasimhan 2
1. Create materialized view "pplan_mv" to display plan_id, plan_name, plan_amount, No_of_sms_free. Change
plan_id=14 amount as “ 3000" in the phone_ plan table. Write appropriate statement, the phone_plan table
modification reflects in the "pplan_mv".
2. Write appropriate statement to insert below information only in "pplan_mv1" materialized view not in
phone_plan table.
Create appropriate materialized view statement for the given below phone_plan table
Plan_id Plan_name Plan_amount
(Rs.)
Expiry date No_of_sms_free
11 Group members 1000 10-oct-2017 50
12 Monthly gold plan 1500 12-jan-2017 60
13 SMS users 800 10-apr-2017 100
14 Student plan 300 5-aug-2017 60
3. Dr. Girija Narasimhan 3
3. Create materialized view "pplan_mv2" using refresh complete and using phone_plan table, change
plan_amount=900 in the plan_id=11 and use appropriate refresh option in the "pplan_mv2" after
refresh also rowid should be same for plan_id=11.
4. Insert comment "this is my second mv" in the "pplan_mv2" and delete "pplan_mv"
5. Create materialized view log on phone_plan to display row_id, plan_id, plan_name, old and new
value after updating No_of_sms_free =150 in plan_id=13. [hint: both create and display statement]
6. Create materialized view "pplan_mv3" using appropriate build method which don't have result
set.
7. Display the status of all the materialized view created earlier and change pplan_mv3 status should
be "valid" in the compile_state column.
8. Display the highest No_of_sms_free, plan_id, plan_name in "pplan_mv5" and delete the comment
in pplan_mv2
4. Question 1
Create materialized view "pplan_mv" to display plan_id, plan_name, plan_amount,
No_of_sms_free.
Create materialized view pplan_mv from phone_plan as select * from phone_plan
Change plan_id=14 amount as “ 3000" in the phone_ plan table.
update phone_plan set plan_amount = ‘3000’ where plan_id=14;
Write appropriate statement, the phone_plan table modification reflects in the "pplan_mv".
execute dbms_mview.refresh(‘pplan_mv’);
Dr. Girija Narasimhan 4
5. Plan_id Plan_name Plan_amount Expiry date No_of_sms_free
15 Sliver plan 400 14-oct-2017 45
Write appropriate statement to insert below information only in "pplan_mv1" materialized view
not in phone_plan table.
Create materialized view pplan_mv1 for update as select * from phone_plan;
INSERT into pplan_mv1 values(15,’Sliver plan’,’400’,’14-oct-2017’,45);
Question 2
Dr. Girija Narasimhan 5
6. Question 3
Create materialized view "pplan_mv2" using refresh complete and using
phone_plan table, change plan_amount=900 in the plan_id=11 and use
appropriate refresh option in the "pplan_mv2" after refresh also rowid
should be same for plan_id=11.
Create materialized view pplan_mv2 refresh complete as select * from
phone_plan;
update phone_plan set plan_amount = ‘900’ where plan_id=11;
Execute DBMS_MVIEW.REFRESH(LIST => 'pplan_mv2', method=>'F');
Dr. Girija Narasimhan 6
7. Question 4
Insert comment "this is my second mv" in the "pplan_mv2"
comment on materialized view pplan_mv2 is 'This is my second mv';
delete "pplan_mv"
drop materialized view pplan_mv;
Dr. Girija Narasimhan 7
8. Question 5
Create materialized view log on phone_plan to display row_id, plan_id, plan_name,
old and new value after updating No_of_sms_free =150 in plan_id=13. [hint: both
create and display statement]
Create materialized view log on phone_plan with row_id,primary key including new
values;
update phone_plan set No_of_sms_free= 150 where plan_id=13;
Select M_row$$,plan_id,plan_name,old_news$$ from mlog$_phone_plan
Dr. Girija Narasimhan 8
9. Question 6
Create materialized view "pplan_mv3" using appropriate build method which don't have result
set.
Create materialized view pplan_mv3 build deferred as select * from phone_plan
Question 7
Display the status of all the materialized view created earlier and change pplan_mv3 status
should be "valid" in the compile_state column.
ALTER MATERIALIZED VIEW pplan_mv3 COMPILE;
SELECT MVIEW_NAME, STALENESS, LAST_REFRESH_TYPE, COMPILE_STATE FROM USER_MVIEWS
ORDER BY MVIEW_NAME;
Dr. Girija Narasimhan 9
10. Question 8
Display the highest No_of_sms_free, plan_id, plan_name in "pplan_mv5"
Create materialized view pplan_mv5 as select Max(No_of_sms_free), plan_id,
plan_name from phone_plan
Delete the comment in pplan_mv2
comment on materialized view pplan_mv2 is ‘ ‘;
Dr. Girija Narasimhan 10