You are on page 1of 7

What Does View Mean?

A view is a subset of a database that is generated from a query and stored


as a permanent object. Although the definition of a view is permanent, the
data contained therein is dynamic depending on the point in time at which
the view is accessed.

Views represent a subset of the data contained in a table. They can join and
simplify multiple tables into one virtual table. They take up very little storage
space because the database contains only the view definition, not the data.
Furthermore, they can provide results for different calculations (like sum and
average) along with the stored data, and can limit the degree to which
tables are exposed to the outer world.

Views can provide advantages over tables:

 Views can represent a subset of the data contained in a table. Consequently, a view
can limit the degree of exposure of the underlying tables to the outer world: a given
user may have permission to query the view, while denied access to the rest of the
base table.
 Views can join and simplify multiple tables into a single virtual table.
 Views can act as aggregated tables, where the database engine aggregates data
(sum, average, etc.) and presents the calculated results as part of the data.
 Views can hide the complexity of data. For example, a view could appear as
Sales2000 or Sales2001, transparently partitioning the actual underlying table.
 Views take very little space to store; the database contains only the definition of a
view, not a copy of all the data that it presents.
 Depending on the SQL engine used, views can provide extra security.
Just as a function (in programming) can provide abstraction, so can a database view. In
another parallel with functions, database users can manipulate nested views, thus one view
can aggregate data from other views. Without the use of views, the normalization of databases
above second normal form would become much more difficult. Views can make it easier to
create lossless join decomposition.

A view is a virtual table that combines data from one or more tables or other views.
Views are created by SQL queries that are then stored as permanent query objects in
the database. Thus, a view is a “virtual table” - the results returned by a view look like
the rows and columns of a regular table, but this “table” only exists as the result of
running the query that defines the view. A regular view does not store any data in the
database (but see below).

The main purpose of a view in SQL is thus to combine data from multiple sources in a
useful way without having to create yet another database table to store that data. The
multiple sources can include tables and view from other database servers.

Since the view is defined by a query, you can use a view to constrain what data is
returned from the source tables and views used to generate the view. A view allows the
view author
to return data an end user needs while protecting possibly sensitive data in the
source tables/views the author does not want revealed.

A view creates a logical table and that table can be the result of any SQL statement.
Because of this 5 categories of options come to mind that developers employ:

 Limiting the visibility of columns (via select) or rows (via where) to just
those pertinent to a task
 Combining rows (via union) and or columns (via join) from multiple tables
into one logical table.
 Aggregating rows (via Group BY and Having) into a more distinct
presentation pulled from a table with finer detail.
 Renaming or decoding either columns (using AS) or rows (using JOIN, IF,
CASE or Oracle’s DECODE).
 Combing any of the above with security settings, access can be locked
down to ensure a user only has access to what they are authorized.

An Oracle VIEW, in essence, is a virtual table that does not physically exist. Rather, it
is created by a query joining one or more tables.

Create VIEW

Syntax
The syntax for the CREATE VIEW Statement in Oracle/PLSQL is:

CREATE VIEW view_name AS SELECT columns


FROM tables
[WHERE conditions];

view_name
The name of the Oracle VIEW that you wish to create.
WHERE conditions
Optional. The conditions that must be met for the records to be included in the VIEW
.
Example
Here is an example of how to use the Oracle CREATE VIEW :

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price FROM
suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id WHERE
suppliers.supplier_name = 'Microsoft';

This Oracle CREATE VIEW example would create a virtual table based on the result set
of the SELECT statement. You can now query the Oracle VIEW as follows:

SELECT *
FROM sup_orders;

Update VIEW
You can modify the definition of an Oracle VIEW without dropping it by using the Oracle
CREATE OR REPLACE VIEW Statement.

Syntax
The syntax for the CREATE OR REPLACE VIEW Statement in Oracle/PLSQL is:

CREATE OR REPLACE VIEW view_name AS SELECT columns


FROM table
WHERE conditions;

view_name
The name of the Oracle VIEW that you wish to create or replace.

Example
Here is an example of how you would use the Oracle CREATE OR REPLACE VIEW
Statement:

CREATE or REPLACE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price FROM
suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id WHERE
suppliers.supplier_name = 'Apple';

This Oracle CREATE OR REPLACE VIEW example would update the definition of the
Oracle VIEW called sup_orders without dropping it. If the Oracle VIEW did not yet exist,
the VIEW would merely be created for the first time.

Drop VIEW
Once an Oracle VIEW has been created, you can drop it with the Oracle DROP VIEW
Statement.

Syntax
The syntax for the DROP VIEW Statement in Oracle/PLSQL is:

DROP VIEW view_name;

view_name
The name of the view that you wish to drop.

Example
Here is an example of how to use the Oracle DROP VIEW Statement:

DROP VIEW sup_orders;

This Oracle DROP VIEW example would drop/delete the Oracle VIEW called
sup_orders.
t91wn;
914:.e
REPLACE fi --- F_O_ .. i i8'
- 'l"'.,.--- --- R_CE
..
CREA ---- i--- ----
1 TE ..

subquery_
subquery H-' iestriction_clause ' ll

Description of the illustration


create_view.git

object_view_clause::
=

OBJE IDENTIFI
CT ER

out_ol_ire_cons traint 1-

attribute inlire_constraint
Description of tile iluslralioo object_view_dause gif

(inline_ constraint::= and


out_ot_line_constraint::= )
Table 1

Vie
w

Table 2

View created from


Table land Table-2

You might also like