问题描述
什么是Oracle中的视图?
What is a view in Oracle?
推荐答案
A 在Oracle中查看系统只是存储在内存中的SQL语句的表示,以便可以轻松地重新使用。例如,如果我们经常发出以下查询:
A View in Oracle and 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
SELECT customerid, customername FROM customers WHERE countryid='US';
要创建视图,请使用 CREATE VIEW命令
CREATE VIEW view_uscustomers
AS
SELECT customerid, customername FROM customers WHERE countryid='US';
此命令创建一个名为view_uscustomers的新视图。请注意,除了定义此视图的数据字典条目外,此命令不会导致任何实际存储在数据库中。这意味着每次查询此视图时,Oracle都必须出去执行视图并查询数据库数据。我们可以这样查询视图:
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:
SELECT * FROM view_uscustomers WHERE customerid BETWEEN 100 AND 200;
Oracle会将查询转换为:
And Oracle will transform the query into this:
SELECT *
FROM (select customerid, customername from customers WHERE countryid='US')
WHERE customerid BETWEEN 100 AND 200
使用视图的好处
- 正在使用的代码的通用性。因为一个视图是基于一个公共的SQL集合,这意味着当它被调用时,它不太可能需要解析。
- 安全性。视图长期以来被用于隐藏实际包含您正在查询的数据的表。此外,视图可用于限制给定用户有权访问的列。
- 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
您可以在本文中找到有关。
You can find advanced topics in this article about "How to Create and Manage Views in Oracle."
这篇关于什么是Oracle中的View?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!