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
What does the file extension accdb stand for?
Can we use ddl statements in stored procedure sql server?
How to change sql*plus system settings?
Is there a way to automate sql execution from the command-line, batch job or shell script?
how does a local variable is defined using t-sql? : Transact sql
What is dba in sql? : SQL DBA
Can we use distinct and group by together?
differentiate between float and double. : Sql dba
Is sql a programming?
Why function is used in sql?
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?
What is the most important ddl statements in sql are?
How do I turn a list into a table?
What is nvl?
What is cursor in pl sql with examples?