Updated on 2023-10-31 GMT+08:00

Creating and Managing Views

Views allow users to save queries. Views are not physically stored on disks. Queries to a view run as subqueries. A database only stores the definition of a view and does not store its data. The data is still stored in the original base table. If data in the base table changes, the data in the view changes accordingly. In this sense, a view is like a window through which users can know their interested data and data changes in the database. A view is triggered every time it is referenced.

Creating a view

Run the CREATE VIEW command to create a view.

The OR REPLACE parameter in this command is optional. It indicates that if the view exists, the new view will replace the existing view.

View Details

  • View the MyView view. Real-time data will be returned.
  • Run the following command to query the views in the current user:
  • Run the following command to query all views:
  • View details about a specified view.
    Run the following command to view details about the dba_users view:

Rebuilding a View

Run the ALTER VIEW command to rebuild a view without entering query statements.

Deleting a View

Run the DROP VIEW command to delete a view.

DROP VIEW ... The CASCADE command can be used to delete objects that depend on the view. For example, view A depends on view B. If view B is deleted, view A will also be deleted. Without the CASCADE option, the DROP VIEW command will fail.