Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[learning] SQL Basics-015-View

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Nature: Logical data sets, no real data

2. Type

Simple view: no functions, no aggregates; DML is generally acceptable

Complex View: uses functions and aggregates; cannot accept DML

3. Principle

oracle accesses the user_views data dictionary, finds the subquery of the view, executes it, and returns the data;

Access to the view is actually access to the base table;

A view is a subquery stored in a data dictionary.

4. Creation

Premise: create view permission

Grammar:

Parameters:

force: Creates a view even if a schedule does not exist in the subquery.

noforce: Default, raises an error if the schedule does not exist.

check with check option and constraint, check where condition when creating view when dml operation is performed. Ensure that DML operates within a specific scope

With read only queries can be made, base tables cannot be modified through views. Disable DML operations

5. Application examples

Query Tablespace Usage

create view tablesp_usage as

select a.tablespace_name as tablespace_name,

to_char(a.total/1024/1024,99999999) as total_mb,

to_char((a.total-b.free)/1024/1024,99999999) use_mb,

to_char(b.free/1024/1024,99999999) as free_mb,

to_char(((total-free)/total)*100,999.99) as "Used %"

from

(select tablespace_name,sum(bytes) as total from dba_data_files

group by tablespace_name) a,

(select tablespace_name,sum(bytes) as free from dba_free_space

group by tablespace_name) b

where a.tablespace_name=b.tablespace_name order by 5 desc;

6, deleted

Drop view does not delete base table data

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report