database Oracle 中的视图是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/256700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:03:49  来源:igfitidea点击:

What is a View in Oracle?

databaseoracleviews

提问by splattne

What is a view in Oracle?

Oracle 中的视图是什么?

回答by splattne

A View in Oracleand in other database systems is simply the representation of a SQL statement that is stored in memory so that it can easily be re-used. For example, if we frequently issue the following query

一个视图中的Oracle和其他数据库系统仅仅是存储在内存中,以便它可以很容易地被重新使用的SQL语句的代表性。例如,如果我们经常发出以下查询

SELECT customerid, customername FROM customers WHERE countryid='US';

To create a view use the CREATE VIEW commandas seen in this example

要创建视图,请使用CREATE VIEW 命令,如本例所示

CREATE VIEW view_uscustomers
AS
SELECT customerid, customername FROM customers WHERE countryid='US';

This command creates a new view called view_uscustomers. Note that this command does not result in anything being actually stored in the database at all except for a data dictionary entry that defines this view. This means that every time you query this view, Oracle has to go out and execute the view and query the database data. We can query the view like this:

此命令创建一个名为 view_uscustomers 的新视图。请注意,除了定义此视图的数据字典条目外,此命令根本不会导致任何内容实际存储在数据库中。这意味着每次查询此视图时,Oracle 都必须出去执行该视图并查询数据库数据。我们可以这样查询视图:

SELECT * FROM view_uscustomers WHERE customerid BETWEEN 100 AND 200;

And Oracle will transform the query into this:

Oracle 会将查询转换为:

SELECT * 
FROM (select customerid, customername from customers WHERE countryid='US') 
WHERE customerid BETWEEN 100 AND 200

Benefits of using Views

使用视图的好处

  • Commonality of code being used. Since a view is based on one common set of SQL, this means that when it is called it's less likely to require parsing.
  • Security. Views have long been used to hide the tables that actually contain the data you are querying. Also, views can be used to restrict the columns that a given user has access to.
  • Predicate pushing
  • 正在使用的代码的通用性。由于视图基于一组通用 SQL,这意味着在调用它时不太可能需要解析。
  • 安全。长期以来,视图一直用于隐藏实际包含您正在查询的数据的表。此外,视图可用于限制给定用户有权访问的列。
  • 谓词推送

You can find advanced topics in this article about "How to Create and Manage Views in Oracle."

您可以在这篇关于“如何在 Oracle 中创建和管理视图”的文章中找到高级主题。

回答by hamishmcn

If you like the idea of Views, but are worried about performance you can get Oracle to create a cached table representing the view which oracle keeps up to date.
See materialized views

如果您喜欢视图的想法,但又担心性能,您可以让 Oracle 创建一个缓存表,代表 oracle 保持最新的视图。
查看物化视图

回答by feel good and programming

regular view----->short name for a query,no additional space is used here

常规视图----->查询的简称,这里没有使用额外的空间

Materialised view---->similar to creating table whose data will refresh periodically based on data query used for creating the view

物化视图---->类似于创建表,其数据会根据用于创建视图的数据查询定期刷新

回答by jassi

A view is a virtual table, which provides access to a subset of column from one or more table. A view can derive its data from one or more table. An output of query can be stored as a view. View act like small a table but it does not physically take any space. View is good way to present data in particular users from accessing the table directly. A view in oracle is nothing but a stored sql scripts. Views itself contain no data.

视图是一个虚拟表,它提供对一个或多个表中列的子集的访问。视图可以从一个或多个表派生其数据。查询的输出可以存储为视图。视图就像一张小桌子,但它在物理上不占用任何空间。视图是通过直接访问表来呈现特定用户数据的好方法。oracle 中的视图只不过是存储的 sql 脚本。视图本身不包含任何数据。

回答by shubham

A view is simply any SELECTquery that has been given a name and saved in the database. For this reason, a view is sometimes called a named query or a stored query. To create a view, you use the SQL syntax:

视图只是SELECT已给定名称并保存在数据库中的任何查询。因此,视图有时称为命名查询或存储查询。要创建视图,请使用 SQL 语法:

     CREATE OR REPLACE VIEW <view_name> AS
     SELECT <any valid select query>;