Question

I am having a list of materialized views. I want to create a package that will contain all views inside this so that whenever needed I can refresh package.

Was it helpful?

Solution

I have created the packages as per below:

---- Creating specification
CREATE OR REPLACE PACKAGE SM_OWN.mv_refr_pkg
IS
        PROCEDURE PROC_MV_REFRESH;

END mv_refr_pkg;
/

---- Creating BODY
CREATE OR REPLACE PACKAGE BODY SM_OWN.mv_refr_pkg
IS

PROCEDURE PROC_MV_REFRESH
IS
BEGIN

FOR mv_name IN
  (SELECT NAME
   FROM sys.dba_dependencies
   WHERE OWNER = 'SM_OWN'
     AND referenced_name='SM_TRANSFER'
     AND TYPE='MATERIALIZED VIEW')

        LOOP
                DBMS_OUTPUT.PUT_LINE(systimestamp || ' Refreshing materialized view SM_OWN.'||mv_name.Name );
                DBMS_SNAPSHOT.REFRESH('SM_OWN.'||mv_name.Name);
        END LOOP;

END PROC_MV_REFRESH;
END;
/


How to Run:
set serveroutput on ;
execute SM_OWN.mv_refr_pkg.PROC_MV_REFRESH;

OTHER TIPS

Do you mean you want to create a code that refreshes all the mviews in your schema?

something like

Create procedure mv_ref is
begin
 for i in (select mview_name from user_mviews) loop
  dbms_mview.(i.mview_name,'f'); -- or whatever method you use
 end loop;
end;

I don't have Oracle installed here - so if it does not compile, you should be able to get the idea from it...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top