Friday, 22 July 2011

VIEW's in sql /oracle


Basic Info of VIEWè

·         A view is a virtual table.
·         It is based on the result-set of an SQL statement.
·         A view contains rows and columns, just like a  table.
·         View’s are created from table or another view.
·         The fields in a view are fields from one or more l tables in the database.
·         You can add SQL functions, WHERE, and JOIN statements to a view.

Difference Between TABLE and VIEWè
·         A table has a set of definition, and it physically stores the data.
·         A view also has a set of definitions, which is build from  table or other view,  
and it does not physically store the data.

SYNTAX->

CREATE or replace VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

EXAMPLE->

CREATE or replace VIEW  test1_v
AS
Select empno , ename ,salary
From emp
Where salary>5000;


- The above example create a view(test1_v) from table (emp).
-  Like table you can select view using
  “Select * from view_name”
Ex- select * from test1_v;
Result=>

EMPNO          ENAME          SALARY
1                      AMOL             15000
2                      ROHIT             10000
3                      VEENA           12000



1 comment: