A view can be created even if the defining query of the view cannot be executed. We call such a view as view with errors.
For example, if a view refers to a non-existent table or an invalid column of an existing table or if the owner of the view does not have the required privileges, then the view can still be created and entered into the data dictionary.
We can create such views (i.e. view with errors) by using the FORCE option in the CREATE VIEW command:
Oracle Sql Force View Syntax:
CREATE [OR REPLACE] [FORCE] VIEW <view name>
Note: When Force command is used in the view syntax then even if select statement is invalid, VIEW gets created successfully.
Example: – In this example we are trying to create a view using a table that does not exist in the database.
/* dummy_table is not available in the database*/
CREATE OR REPLACE FORCE VIEW na_view
AS SELECT * FROM dummy_table;
Warning: View created with compilation errors.
Specify FORCE if we want to create the view regardless of whether the base tables of the view or the referenced object types exist or the owner of the schema containing the view has privileges on them.
The advantage of force view is that in future if view script becomes valid, we can start using the view.
Note:force view is use basically for the situation when we create a view using a table but the table is not created at that time we use force command;