Skip to Main Content
  • Questions
  • How to exclude mviews that are not being updated in the script?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Priscila.

Asked: March 09, 2017 - 2:50 pm UTC

Last updated: March 10, 2017 - 3:56 am UTC

Version: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production

Viewed 1000+ times

You Asked

Hello,

I have a scheduled job on Oracle GRID to send alerts when any mviews are not updated. But I have three mviews that are not beeig updated and I canno´t change it for now. So I need to change my script to exclude these three mviews (only those three) to not get alerts every day.

I have no idea how to make this change.

Can you help me, please?


See the script below:


----------

variable exit_code number;
set serveroutput on
DECLARE
v_checa number;
cursor c1 is select mview_name,last_refresh_Date
FROM dba_mviews WHERE owner = 'TESTE' and last_refresh_date < sysdate - 1 ;

BEGIN
:exit_code := 0;
SELECT count(*) into v_checa
FROM dba_mviews WHERE owner = 'TESTE' and last_refresh_date < sysdate - 1 ;

if v_checa >=1 then
for mview_rec in c1 loop
dbms_output.put_line('Mview '||mview_rec.mview_name||' last update '||to_char(mview_rec.last_refresh_date,'dd/mm/yyyy hh24:mi'));

end loop;
:exit_code := 1;
end if;
end;
/

exit :exit_code;



-------------------------

Thank you very much

and Connor said...

Wouldn't you just set them in your cursor ?

cursor C is 
  select mview_name,last_refresh_Date
  FROM dba_mviews 
  WHERE owner = 'TESTE' 
  and last_refresh_date < sysdate - 1 
  and mview_name not in ('A','B','C');


I wouldn't bother with the count(*) part - either you'll get rows in the cursor loop or not.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

DBMS_OUTPUT

More on PL/SQL routine DBMS_OUTPUT here