Dealing with Materialized Views and Refresh Groups in Oracle

Oracle Database Administration
Post Reply
User avatar
jimb
Site Admin
Posts: 6146
Joined: Thu Jan 19, 2012 1:10 pm
Location: New Delhi, India
Contact:

Dealing with Materialized Views and Refresh Groups in Oracle

Post by jimb »

Dealing with Materialized Views and Creating Refresh Groups in Oracle.

Important Views:
select * from DBA_REFRESH; -- describes all refresh groups in the database
select * from DBA_REFRESH_CHILDREN; -- lists all of the objects in all refresh groups in the database
select * from dba_jobs; -- describes all jobs in the database

DBMS_REFRESH - Procedure MAKE
The MAKE procedure is used to create a new Refresh group.

We will make a refresh group Test_Refresh_Group_1:

Code: Select all

SQL> BEGIN DBMS_REFRESH.MAKE(
	name => 'Test_Refresh_Group_1',
	list => ' Daily_Sales_MV, Daily_Expenses_MV',
	next_date => sysdate,
	interval => 'sysdate + 1/24');
	END;
/
Test_Refresh_Group_1 has two views in its group, Daily_Sales_MV and Daily_Expenses_MV. Both of these views will be refreshed daily at an interval of one (1) hour.

DBMS_REFRESH - Procedure ADD
Add a snapshot/materialized view to the already existing refresh group:

Code: Select all

SQL> BEGIN DBMS_REFRESH.ADD(
	name => 'Test_Refresh_Group_1',
	list => 'Weekly_Report_MV');
	END;
/
Test_Refresh_Group_1 now has three views in its group, Daily_Sales_MV, Daily_Expenses_MV and Weekly_Report_MV (the newly added view). All of these views will be refreshed daily at an interval of one (1) hour.

DBMS_REFRESH - Procedure SUBTRACT
Removes a snapshot/materialized view from the already existing refresh group.

Code: Select all

SQL> BEGIN DBMS_REFRESH.SUBTRACT(
	name => 'Test_Refresh_Group_1',
	list => 'Daily_Sales_MV');
	END;
/
Test_Refresh_Group_1 now has two views in its group, Daily_Expenses_MV and Weekly_Report_MV. We have removed Daily_Sales_MV from the refresh group, Test_Refresh_Group_1.

DBMS_REFRESH - Procedure REFRESH
Manually refreshes the already existing refresh group.

Code: Select all

SQL> BEGIN DBMS_REFRESH.REFRESH(
	name => 'Test_Refresh_Group_1');
	END;
/
DBMS_REFRESH - Procedure CHANGE
The CHANGE procedure is used to change the refresh interval of the refresh group.

Code: Select all

SQL> BEGIN DBMS_REFRESH.CHANGE(
	name => 'Test_Refresh_Group_1',
	next_date => NULL,
	interval => 'sysdate+1/96');
	END;
/
The views in Test_Refresh_Group_1 will now be refreshed at an interval of 15 minutes.

DBMS_REFRESH - Procedure DESTROY
Removes all materialized views from the refresh group and deletes the refresh group.

Code: Select all

SQL> BEGIN DBMS_REFRESH.DESTROY(
	name => 'Test_Refresh_Group_1');
	END;
/
Oracle Database Administration Forums
http://www.oracle-forums.com/
xaeresis
Posts: 196117
Joined: Wed Oct 04, 2023 2:39 pm

Re: Dealing with Materialized Views and Refresh Groups in Oracle

Post by xaeresis »

xaeresis
Posts: 196117
Joined: Wed Oct 04, 2023 2:39 pm

Re: Dealing with Materialized Views and Refresh Groups in Oracle

Post by xaeresis »

Post Reply