what is 'force view'?

Answer Posted / m arun kumar

FORCE
The FORCE option of the CREATE VIEW statement can be used
to create the object even if one of the underlying objects
(i.e. referenced within the view) do not exist.

This can be useful if the views are created before the
underlying objects in creation scripts etc.
/* Try to create a view against a table which does not
exist */

SQL> CREATE OR REPLACE VIEW test_view
2 AS
3 SELECT * FROM non_existent_table;
SELECT * FROM non_existent_table
*
ERROR at line 3:
ORA-00942: table or view does not exist

/* Hence, the view does not exists */

SQL> SELECT * FROM test_view;
SELECT * FROM test_view
*
ERROR at line 1:
ORA-00942: table or view does not exist

/* Specifying FORCE creates the view object (albeit with
errors) */

SQL> CREATE OR REPLACE FORCE VIEW test_view
2 AS
3 SELECT * FROM non_existent_table;

Warning: View created with compilation errors.

/* Trying to SELECT from the view implies it's been created
*/

SQL> SELECT * FROM test_view;
SELECT * FROM test_view
*
ERROR at line 1:
ORA-04063: view "ORAUSER.TEST_VIEW" has errors

/* Creating the missing object then allows us to select
from it */

SQL> CREATE TABLE non_existent_table
2 (
3 a VARCHAR2(10)
4 );

Table created.

SQL> SELECT * FROM test_view;

no rows selected

Is This Answer Correct ?    19 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does the file extension accdb stand for?

545


Can we use ddl statements in stored procedure sql server?

511


How to change sql*plus system settings?

540


Is there a way to automate sql execution from the command-line, batch job or shell script?

551


how does a local variable is defined using t-sql? : Transact sql

537






What is dba in sql? : SQL DBA

527


Can we use distinct and group by together?

582


differentiate between float and double. : Sql dba

553


Is sql a programming?

543


Why function is used in sql?

515


How we can create a table in pl/sql block. Insert records into it? Is it possible by some procedure or function? Please give example?

589


What is the most important ddl statements in sql are?

519


How do I turn a list into a table?

504


What is nvl?

607


What is cursor in pl sql with examples?

475