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
Oracle 10g Tutorials - Creating Views, Altering, Dropping and Replacing Views - Page 3
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.
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.
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).
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
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
|
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 |
|
CREATE OR REPLACE VIEW DEPT AS (SELECT DISTINCT emp_num from emp MINUS SELECT DISTINCT emp_num FROM managers); |