Oracle 中的视图是什么? [英] What is a View in Oracle?

查看:26
本文介绍了Oracle 中的视图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle 中的视图是什么?

What is a view in Oracle?

推荐答案

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 命令,如本例所示

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

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,这意味着当它被调用时,它不太可能需要解析.
  • 安全.长期以来,视图一直用于隐藏实际包含您正在查询的数据的表.此外,视图可用于限制给定用户有权访问的列.
  • 谓词推送

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

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

这篇关于Oracle 中的视图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆