Oracle learning notes View

Source: Internet
Author: User
Tags dname
1. What is a view? A view is also called a virtual table. A logical expression VIEW of a group of data corresponds to a SELECT statement.

1. What is a view? A view is also called a virtual table. A logical expression VIEW of a group of data corresponds to a SELECT statement.

1. What is a view?

A view is also called a virtual table. It is a logical expression of a group of data.

A view corresponds to a SELECT statement, and the result set is assigned a name, that is, the view name.

The view itself does not contain any data. It is only a query statement mapped to the base table. When the base table data changes, the view data also changes.

Role: reuse code to protect data

2. You must have the permission grant create view to user scott to create a VIEW;

Create view view_name alias

A function is called a simple view.

Complex view containing function expressions

Connecting views based on multiple tables

Or replace to update a view if it exists

Syntax

Create or replace view name SELECT statement

Hide column names by adding aliases in SELECT statements

Create or replace view v_emp_10 as select empno id, ename name, sal salary, deptno FROM emp WHERE deptno = 10;

View view structure DESC view name

After adding an alias, you can only use the alias to query the view's SELECT name, salary, and work FROM v_emp_10;

Add with check option to prevent dirty data from being inserted to the base table in simple view mode.

Create or replace view v_emp_10 as select empno id,

Ename name, sal salary, deptno FROM emp WHERE deptno = 10 with check option;

Complex view Creation

Create view v_emp_salary

AS

SELECT d. dname,

AVG (e. sal) avg_sal,

SUM (e. sal) sum_sal,

MAX (e. sal) max_sal,

MIN (e. sal) min_sal

FROM emp e JOIN dept d ON e. deptno = d. deptno group by d. dname;

Query complex views

SELECT * FROM v_emp_salary;

Complex views do not allow DML operations

This article permanently updates the link address:

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.