Exforsys.com
 
Home Tutorials Oracle 10g
 

Oracle 10g Tutorials - Creating Views, Altering, Dropping and Replacing Views

 

Oracle 10g Tutorials - Creating Views, Altering, Dropping and Replacing Views - Page 2

Page 2 of 3


Join Views

You can also create views that specify more than one base table or view in the FROM clause. These are called join views. The following statement creates the division1_staff view that joins data from the emp and dept tables:


CREATE VIEW division1_staff AS
SELECT ename, empno, job, dname
FROM emp, dept
WHERE emp.deptno IN (10, 30)
AND emp.deptno = dept.deptno;



Figure 15. Creating a join view


An updatable join view is a join view where UPDATE, INSERT, and DELETE operations are allowed.


Expansion of Defining Queries at View Creation Time

When a view is created, Oracle Database expands any wildcard (*) in a top-level view query into a column list. The resulting query is stored in the data dictionary; any subqueries are left intact. The column names in an expanded column list are enclosed in quote marks to account for the possibility that the columns of the base object were originally entered with quotes and require them for the query to be syntactically correct.


As an example, assume that the dept view is created as follows:


CREATE VIEW dept AS SELECT * FROM scott.dept;


The database stores the defining query of the dept view as:


SELECT "DEPTNO", "DNAME", "LOC" FROM scott.dept;


Views created with errors do not have wildcards expanded. However, if the view is eventually compiled without errors, wildcards in the defining query are expanded.


Creating Views with Errors

If there are no syntax errors in a CREATE VIEW statement, the database can create the view even if the defining query of the view cannot be executed. In this case, the view is considered "created with errors." For example, when a view is created that refers to a nonexistent table or an invalid column of an existing table, or when the view owner does not have the required privileges, the view can be created anyway and entered into the data dictionary. However, the view is not yet usable.


To create a view with errors, you must include the FORCE clause of the CREATE VIEW statement.


CREATE FORCE VIEW AS ...;



By default, views with errors are created as INVALID. When you try to create such a view, the database returns a message indicating the view was created with errors. If conditions later change so that the query of an invalid view can be executed, the view can be recompiled and be made valid (usable).


Altering Views

You use the ALTER VIEW statement only to explicitly recompile a view that is invalid.


The ALTER VIEW statement lets you locate recompilation errors before run time. To ensure that the alteration does not affect the view or other objects that depend on it, you can explicitly recompile a view after altering one of its base tables.


To use the ALTER VIEW statement, the view must be in your schema, or you must have the ALTER ANY TABLE system privilege


Dropping Views

You can drop any view contained in your schema. To drop a view in another user's schema, you must have the DROP ANY VIEW system privilege. Drop a view using the DROP VIEW statement. For example, the following statement drops the emp_dept view:


DROP VIEW emp_dept;




Next Page: Oracle 10g Tutorials - Creating Views, Altering, Dropping and Replacing Views - Page 3


Read Next: Oracle 10g Tutorials- Updating Views



 

 

Comments


Jay said:

  I am trying to create a view with MINUS between two SELECT queries .
Say for example,
CREATE OR REPLACE VIEW DEPT AS
(SELECT DISTINCT emp_num from emp)
MINUS
(SELECT DISTINCT emp_num FROM managers)
/

But an exception is raised saying
SP-0042 - unkown command "MINUS"

Can anyone please let me if MINUS is a valid operation while creating a view?

Thanks in advance,
Jay
February 11, 2009, 1:24 am

Proprietario said:

  CREATE OR REPLACE VIEW DEPT AS
(SELECT DISTINCT emp_num from emp
MINUS
SELECT DISTINCT emp_num FROM managers);
March 25, 2009, 1:19 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape