  CREATE MATERIALIZED VIEW V_PTLETTER_MU ("PtLetter", "Patient", "Description", "Date", "Deleted", "AppUser", "AppDate", "Status")
  BUILD IMMEDIATE
  REFRESH ON DEMAND
  AS
  SELECT ptl."PtLetter", ptl."Patient", ptl."Description", ptl."Date", ptl."Deleted", ptl."AppUser", ptl."AppDate", ptl."Status"
  FROM PTLDETAILS ptl
  WHERE 1=1
  AND((NLS_UPPER(ptl."Description") LIKE '%CLINICAL VISIT SUMMARY%') OR (NLS_UPPER(ptl."Description") LIKE '%MU_%'));

  CREATE INDEX V_PTLETTER_MU_PATIENT ON V_PTLETTER_MU("Patient"); 
  CREATE UNIQUE INDEX V_PTLETTER_MU_PTLETTER ON V_PTLETTER_MU("PtLetter"); 

create or replace function REFRESH_V_PTLETTER_MU()
returns trigger language 'edbspl'
    COST 100
    VOLATILE NOT LEAKPROOF SECURITY DEFINER
as $BODY$
begin
    refresh materialized view V_PTLETTER_MU;
    return null;
end $BODY$;

create trigger REFRESH_V_PTLETTER_MU
after insert or update or delete or truncate
on PTLDETAILS for each statement 
execute procedure REFRESH_V_PTLETTER_MU();
