1. View concept: A view is a logical structure that does not contain any data. It is a named SELECT statement. The underlying data can be seen through the view, but the view and data are independent of each other. 2. You must have the DBA permission to create a view. 3. Syntax: Create [or replace] [force | noforce] view [(alias [, alias]...)] as subquery; 4, create or replace indicates that if a view exists, it is replaced; for example, SQL> Create view testview3
2
3 select * From test3; the view has been created. SQL> Create view testview3
2
3 select * From test3;
Create view testview3
*
Row 3 has an error:
ORA-00955: Name modified view used by existing object: SQL> Create or replace view testview3
2
3 select * From test3; the view has been created.
5. Force indicates that a view is created forcibly if the table does not exist. For example, SQL> Create view TT
2
3 select * from TT;
Create view TT
*
Row 3 has an error:
ORA-01731: View definitions with loops SQL> Create Force view TT
2
3 select * from TT; warning: the created view has a compilation error. 6. view the view structure: SQL> DESC testview3;
Is the name empty? Type
-----------------------------------------------------------------------------
Id not null number (38)
Lname varchar2 (20)
Fname varchar2 (20)
7. Create an alias when using an aggregate function to create a view. SQL> Create view testview4
2
3 select ID, sum (ID) from test3
4 group by ID;
Select ID, sum (ID) from test3
*
Row 3 has an error:
ORA-00998: this expression must be named by column alias SQL> Create view testview4
2
3 select ID, sum (ID) test3_id from test3
4 group by ID; view created. 8. Update view: SQL> select * From testview5; test5_id test5_name test5_fname
--------------------------------------------------
3 Kong sales
2 hhsql> Update testview5 set test5_name = 'ONG _ gai'
2 Where test5_id = 3; 1 row has been updated. SQL> select * From testview5; test5_id test5_name test5_fname
--------------------------------------------------
3 kong_gai sales
2 HH