0% found this document useful (0 votes)
35 views3 pages

Views: Some of The Advantages of Using Views

Views are stored SQL queries that are used to present a virtual table from data in one or more real tables. Views can be simple, containing a single base table, or complex, containing joins across multiple tables. Simple views allow DML operations directly on the view, while complex views require triggers to handle DML. Views provide benefits like security, information hiding, and reducing SQL complexity, but can cause issues if nested too deeply.

Uploaded by

Parithi Vignesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Views: Some of The Advantages of Using Views

Views are stored SQL queries that are used to present a virtual table from data in one or more real tables. Views can be simple, containing a single base table, or complex, containing joins across multiple tables. Simple views allow DML operations directly on the view, while complex views require triggers to handle DML. Views provide benefits like security, information hiding, and reducing SQL complexity, but can cause issues if nested too deeply.

Uploaded by

Parithi Vignesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Some of the advantages of using views:



$educe the com!lexity o SQL statements Share only s!eci ic rows in a table with other users %ide the &A'( and O)&($ o the base table

View details can be queried from the dictionary by querying either



*S($+V,()S ALL+V,()S -.A+V,()S.

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

2$(A0( V,() em!loyee+view AS S(L(20 3 4$O' em!loyees5

Examples: 2
2$(A0( V,() de!artment67 AS S(L(20 irst+name# salary386 annual+salary 4$O' em!loyees

)%($( de!artment+no 9 675

Complex views
2om!lex views can be constructed on more than one base table.

n particular! complex views can contain: 1. 2.


join conditions a "rou! by clause a order by clause One cannot !er orm -'L o!erations a"ainst com!lex views directly.

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/

"E$% &'() clause on a simple view:

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

"E$% &'() clause on a complex view/


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 ),0% $(A- O&L=5

*ith chec+ option


0he ),0% 2%(2< O>0,O& clause s!eci ies the level o checkin" to be done when doin" -'L a"ainst the view. , s!eci ied# every row that is inserted# u!dated or deleted throu"h the view must con orm to the de inition o the view.

,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

You might also like