6.30.2008

View:

A view is simply the representation of a SQL statement that is stored in memory so that it can easily be re-used.

A
view is only a logical structure that contains no data of its own. Instead, a view is like a window that can be used to look at the contents of another table or tables.

To create a view use the create view command as seen in this example:

Example-1:
create table empinfo(
empid number(4),
ename varchar2(20),

deptno number(2));

INSERT Into empinfo VALUES (1,'Rahim',10);

INSERT Into empinfo VALUES (2,'Karim',10);

INSERT Into empinfo VALUES (3,'Jamal',10);

INSERT Into empinfo VALUES (4,'Kamal',10);

CREATE VIEW view_emp
AS
SELECT empid,ename FROM empinfo;

This command create a view view_emp.

Example-2:
Create single table basic view:
CREATE OR REPLACE VIEW single_view AS
SELECT empid AS ID, ename AS NAME
FROM empinfo;

Example-3:
Create Single Table View With WHERE Clause
CREATE OR REPLACE VIEW single_view AS
SELECT empid AS ID, ename AS NAME
FROM empinfo
WHERE ID>100;

Read Only View:

CREATE OR REPLACE VIEW read_only_view AS
SELECT empid, ename
FROM empinfo
WITH READ ONLY;

UPDATE read_only_view
SET ename = 'Nahar'
WHERE ename = 'Rahim';
ORA-01733: virtual column not allowed here

Force view:
Forces The Creation Of A View Even When The View Will Be Invalid. NoForce Is The Default.

-- assuming the table pq does not exist

CREATE OR REPLACE FORCE VIEW view_force AS
SELECT * FROM pq;

-- ignore the error message

DROP view:
DROP VIEW ;
SELECT view_name FROM user_views;

DROP VIEW single_view;

Benefits of oracle view:
Security: Views are used to hide the table name that actually contain the data when you are querying. Again, views can be used to restrict the columns that a given user has access.

Views help to access to the metadata because the names of the views and the columns in them are much more intuitive than the metadata tables on which they are based.

An Oracle 10g database contains
two types of metadata views:
-Data dictionary views
-Dynamic performance views