Professional Documents
Culture Documents
Views
Views
A view derives its data from the tables on which it is based. These tables are called base tables.
All operations performed on a view actually affect the base table of the view.
You can use views in almost the same way as tables. You can query, update, insert into, and delete from
views, just as you can standard tables.
Creating Views:
To create a view in your schema, you must have the CREATE VIEW privilege.
View created.
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
SQL> create view v2 as select ename ,dname from emp natural join dept;
View created.
ENAME DNAME
---------- --------------
SMITH RESEARCH
ALLEN SALES
WARD SALES
JONES RESEARCH
MARTIN SALES
BLAKE SALES
CLARK ACCOUNTING
SCOTT RESEARCH
View created.
SQL> select * from v3;
ENAME LOC
---------- -------------
SMITH DALLAS
ALLEN CHICAGO
WARD CHICAGO
JONES DALLAS
MARTIN CHICAGO
BLAKE CHICAGO
SCOTT DALLAS
View dropped.
Revoke succeeded.
You can use the ROWID pseudocolumn in the SELECT and WHERE clause of a query, these
pseudocolumn values are not actually stored in the database. You cannot insert, update, or delete a
value of the ROWID pseudocolumn.
ID NAME CITY
1A
2B
ROWID
------------------
AAANLZAAEAAAAKNAAA
AAANLZAAEAAAAKNAAB
* UPDATE DEMO80 SET CITY='MUMBAI' WHERE ROWID='AAANLZAAEAAAAKNAAB';
1 row updated.
ID NAME CITY
1A
2B MUMBAI
ID NAME CITY
2B MUMBAI
- The first row selected has a rownum of 1, the second has 2, and so on.
-You can use rownum to limit the number of rows returned by a query,
as in this example:
AAAMfPAAEAAAAAgAAA 1 SMITH
AAAMfPAAEAAAAAgAAB 2 ALLEN
AAAMfPAAEAAAAAgAAC 3 WARD
AAAMfPAAEAAAAAgAAD 4 JONES
AAAMfPAAEAAAAAgAAE 5 MARTIN
AAAMfPAAEAAAAAgAAF 6 BLAKE
AAAMfPAAEAAAAAgAAG 7 CLARK
AAAMfPAAEAAAAAgAAH 8 SCOTT
AAAMfPAAEAAAAAgAAI 9 KING
AAAMfPAAEAAAAAgAAJ 10 TURNER
AAAMfPAAEAAAAAgAAK 11 ADAMS
AAAMfPAAEAAAAAgAAL 12 JAMES
AAAMfPAAEAAAAAgAAM 13 FORD
AAAMfPAAEAAAAAgAAN 14 MILLER
14 rows selected.