Create a view in Oracle

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.