I have a materialized view that I need to redefine the SQL for. We have an external system that hits the view over a db link, and the monster view takes 5 minutes to refresh the data in the view. The only way I know how to redefine the SQL for a view is to drop it and recreate it, but it would be very bad if the external system couldn't find the table, or it didn't have a complete data set. I need to have as little downtime as possible.
Is there any way to do this natively or more elegantly than:
- Create public synonym for materialized view and make everything that uses the view use the synonym instead.
- Create new materialized view with new SQL
- Change the synonym to point to the new view
- Drop the old view.
I've got code to do this dynamically but it is getting really ugly. It seems like there should be a better way to handle this.