如何找到 Oracle 视图的基础列和表名称?
这听起来应该很简单,但事实并非如此!我找不到任何 Oracle(元数据)视图可以提供 Oracle 视图列的基础列和表名称。我发现这样做的唯一方法是解析视图源 SQL(这与精确的科学相去甚远)。
为了解释我想要什么,请考虑我在 SCOTT 模式中创建的以下示例视图:
CREATE OR REPLACE VIEW EMP_DEP
(
EMPLOYEE_NAME,
DEPARTMENT_NAME
)
AS
SELECT
ENAME,
DNAME
FROM
emp a,
dept b
WHERE
a.deptno= b.deptno
/
现在给定视图和列名称 EMP_DEP.DEPARTMENT_NAME,我想获取视图使用的基础表和列名称 DEPT.DNAME。有谁知道不涉及解析视图 SQL 的获取此信息的方法吗?
This sounds like it should be simple to do but not so! There is no Oracle (meta-data) view that I can find that gives the underlying column and table name for an Oracle view column. The only way I have found of doing it is to parse the view source SQL (which is far from and exact science).
Just to explain what I want, consider the following example view which I created in SCOTT schema:
CREATE OR REPLACE VIEW EMP_DEP
(
EMPLOYEE_NAME,
DEPARTMENT_NAME
)
AS
SELECT
ENAME,
DNAME
FROM
emp a,
dept b
WHERE
a.deptno= b.deptno
/
Now given the view and column name EMP_DEP.DEPARTMENT_NAME, I would like to get the underlying table and column name used by the view which is DEPT.DNAME. Does anyone know of a way to get this information that does not involve parsing the view's SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
没有办法,因为每个视图列的定义是一个表达式,而不仅仅是一个表列(通常)。例如,您的视图的 SQL 可能是:
或者
您希望在本示例中看到“底层列”是什么?
There isn't a way, because the definition of each view column is an expression, not (in general) merely a table column. For example, your view's SQL could be:
or perhaps
What would you expect to see for the "underlying columns" in this example?
可以使用查询选择用于创建视图的表:
如果视图列与表列具有相同的列名,请尝试以下查询:
Tables used to created the view can be selected using the query:
If view columns have the same column name of table column, then please try the below query:
由于请求者正在寻找其表的任何实例,而不是针对特定视图,因此我建议:
Since the requester is looking for any instance of his table, and not with respect to a specific view, I would recommend:
定义视图的 sql 可以在 all_views 中找到,
这是获取基础表和列的唯一方法。
The sql that defined the view can be found in all_views
This is the only way to get at the underlying tables and columns.
Oracle 在 11g 中引入了 更细粒度的依赖跟踪。因此数据库知道视图或包主体依赖于哪些表列。然而,他们似乎没有在视图中公开这些数据。但可能有 x$ 表包含该信息。
In 11g Oracle introduced finer grained dependency tracking. So the database knows which table columns a view or package body depends on. However, they don't seem to have exposed this data in a view. But there may be x$ tables with the info.
链接过程可能是一些帮助用于识别依赖关系
DBA_DEPENDENCIES 视图将为您提供视图所基于的表的列表:
The linked procedures may be of some help for identifying dependencies
The DBA_DEPENDENCIES View will give you a list of the tables that a View is based on:
如果您想要视图表和列依赖关系,这很有效:
输出
This works well if you want a views table and column dependencies:
Outputs