A Way For Learning

PL-SQL : View

No comments
View plays an important role for displaying the results of the queries. View is a representation of another table or combinations of tables.We can get the required type of display by using views.
The table from which data is derived to view is called BASE TABLE. Base tables can be either the original tables in the database or view tables.

Any changes made in the view will also effect the view of the base table..View are use to join multiple tables and display the required output view.

SYNTAX of view :
CREATE OR REPLACE VIEW view_name AS
  SELECT columns
  FROM table
  WHERE conditions;
In the above syntax 'REPLACE' is optional because if a view is already created with that name,it will replace the older one with the new one so that we will not get errors.

To drop the view syntax is:
DROP VIEW view_name;

Materialized Views
: A Materialized view is a sub table of a given table or combination tables.One cannot insert or delete the data,but can drop the view.
This view is the replica of the original table.This view has high performance.
Syntax :
CREATE OR REPLACE MATERIALIZED VIEW view_name AS
  SELECT columns
  FROM table
  WHERE conditions;


Read-Only View : This view can only be view and one cannot apply and any DML statements on this view.
Syntax of read-only view:
CREATE OR REPLACE VIEW view_name AS
  SELECT columns
  FROM table
  WHERE conditions
  WITH READ ONLY;

Uses of view :
  • Performance is faster by using views.
  • Complexity of the SQL statements can be reduced.
  • Hiding of data is possible ie Security
  • Change the column names 



No comments :

Post a Comment