Professional Documents
Culture Documents
Views: Some of The Advantages of Using Views
Views: Some of The Advantages of Using Views
A view is a named and validated SQL query which is stored in the Oracle data dictionary. Views do not contain any data - it is just a stored query in the database that can be executed when called. One can think o a view as a virtual table or ma!!in" o data rom one or more tables. Views are use ul or security and in ormation hidin"# but can cause !roblems i nested too dee!ly.
View types
Views can be classi ied as
sim!le com!lex/
Simple views
Sim!le views can only contain a sin"le base table. One can !er orm -'L o!erations directly a"ainst sim!le views. 0hese -'L chan"es are then a!!lied to the view1s base table.
Examples: 1
Examples: 2
2$(A0( V,() de!artment67 AS S(L(20 irst+name# salary386 annual+salary 4$O' em!loyees
Complex views
2om!lex views can be constructed on more than one base table.
0o enable -'L o!erations on com!lex views one needs to write ,&S0(A- O4 tri""ers to tell Oracle how the chan"es relate to the base table:s;.
Examples: 1
2$(A0( V,() sa+com!+view AS S(L(20 em!. irst+name# em!.em!loyee+id# em!.job+id# em!.de!artment+id# de!t.de!artment+name# de!t.location 4$O' em!loyees em! # de!artments de!t5
Examples: 2
2$(A0( V,() sam!le+com!lex+view AS S(L(20 em!. irst+name# em!.em!loyee+id# em!.job+id# em!.de!artment+id# de!t.de!artment+name# de!t.location )%($( em!.de!artment+id9 de!t.de!artment+id5
"ead#only views
*sers can only run S(L(20 and -(S2 statements a"ainst read only views. (xam!les/
2$(A0( V,() clerk :id+number# !erson# de!artment# !osition; AS S(L(20 em!loyee+id# irst+name# de!artment+id# job+id 4$O' em!loyees )%($( job 9 12L($<1 ),0% $(A- O&L=5
,he problem:
S-(. 2$(A0( V,() d67 AS S(L(20 ename# sal# de!tno 4$O' em!6 )%($( de!tno 9 675 View created. SQL? *>-A0( d67 S(0 de!tno 9 875 @ rows u!dated.
,he solution:
S-(. 2$(A0( V,() d67 AS S(L(20 ename# sal# de!tno 4$O' em!6 )%($( de!tno 9 67 6 ),0% 2%(2< O>0,O&5 View created. SQL? *>-A0( d67 S(0 de!tno 9 875 *>-A0( d67 S(0 de!tno 9 87 3 ($$O$ at line 8/ O$A-78A76/ view ),0% 2%(2< O>0,O& where-clause violation