Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the use of views in Oracle

Shulou Source: shulou.com Published: 2022-05-31 14:42:12 09月19日 Update

This article mainly shows you "what is the use of the view in Oracle", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of the view in Oracle" this article.

1. What is a view?

A VIEW, also known as a virtual table, is a logical representation of a set of data.

The view corresponds to a SELECT statement, and the result set is given a name, that is, the view name.

The view itself does not contain any data, but is just a query mapped to the base table. When the base table data changes, the view data is sent with it.

Function: reuse code and protect data

two。 Permission GRANT CREATE VIEW TO user scott is required to create a view

CREATE VIEW view_name alias

Not including functions is called simple view

Contains complex views of function expressions

Join views based on multiple tables

OR REPLACE update view replace if present

Grammar

CREATE OR REPLACE VIEW View name SELECT statement

Hide column names add aliases to SELECT statements

CREATE OR REPLACE VIEW v_emp_10 AS SELECT empno id, ename name,sal salary,deptno deptno FROM emp WHERE deptno=10

View view structure DESC view name

After adding aliases, you can only use aliases to query view SELECT name, salary, job FROM v_emp_10.

Add WITH CHECK OPTION to prevent dirty data from being inserted into the base table in simple view mode

CREATE OR REPLACE VIEW v_emp_10 AS SELECT empno id

Ename name,sal salary,deptno deptno FROM emp WHERE deptno=10 WITH CHECK OPTION

Creation of complex views

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 for complex views

SELECT * FROM v_emp_salary

Complex views do not allow DML operations

The above is all the content of the article "what's the use of views in Oracle?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: View data complexity alias statement content name article query function name change learning help code function just multiple name salary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Shulou Tech Info Shulou Information NVidia