What is the difference between Views and Materialized Views in Oracle?

In Oracle, views and materialized views are both database objects that can be used to present a customized version of data from one or more tables, but they have some important differences:
  • A view is a virtual table that is defined by a SELECT statement. When a view is queried, the SELECT statement is executed, and the result set is returned to the user. 
  • A view does not store data; it simply provides a way to access data from one or more tables in a specific way.
  • A materialized view, on the other hand, is a physical copy of the data from the underlying tables. Materialized views are defined by a SELECT statement, just like views, but they also store the result set of the SELECT statement in a separate table. When a materialized view is queried, the data is retrieved from the stored table rather than being recalculated.
Here are some key differences between views and materialized views in Oracle:
  • Performance: Since materialized views store a copy of the data, they can provide faster query performance than views, especially for complex queries or large data sets.
  • The freshness of data: Views always return the most recent data from the underlying tables, while materialized views can become stale if the data in the underlying tables changes. To keep the data in a materialized view fresh, you can use the "REFRESH" command.
  • Indexing: Materialized views can be indexed for better query performance, but views can't be indexed.
  • Space: Materialized views require additional disk space to store a copy of the data, while views don't.