简体   繁体   English

我的Oracle视图使用了一个不存在的表,但我仍然可以查询它

[英]My Oracle view uses a table that doesn't exist, but I can still query it

I have an Oracle view that uses a table that I cannot find anywhere. 我有一个Oracle视图,它使用我在任何地方都找不到的表。 However, I can still query the view, which I would have thought would be impossible. 但是,我仍然可以查询视图,我认为这是不可能的。

Are the view contents cached somewhere, from when the table still existed, or am I simply not looking hard enough for the table? 视图内容是否缓存在某个地方,从表格仍然存在的时候开始,还是我对表格看起来不够努力?

Just to be clear: I've looked in ALL_TABLES and ALL_OBJECTS and the table (or whatever it is) doesn't appear in either. 为了清楚起见:我已经查看了ALL_TABLES和ALL_OBJECTS,并且表中(或其他任何内容)都没有出现。

This is very possible.. Granting select on a view does not grant select on the underlying tables. 这很有可能。在视图上授予select不会在基础表上授予select。 This allows me to create a view that exposes a couple columns from a table that I don't want you to see all of. 这允许我创建一个视图,从表中公开一些我不希望你看到的列。 You have to have access on the table for it to show up in the ALL_TABLES view. 您必须具有对表的访问权限才能在ALL_TABLES视图中显示它。 If it really is a table, you should be able to find it in the DBA_TABLES view (assuming you have access to the DBA_TABLES view), which has everything and not just tables that your user has privileges on. 如果它确实是一个表,您应该能够在DBA_TABLES视图中找到它(假设您可以访问DBA_TABLES视图),该视图包含所有内容,而不仅仅是您的用户拥有权限的表。

In fact, the ALL_TABLES view is a perfect example of this situtation. 事实上,ALL_TABLES视图就是这种情况的完美例子。 I bet you can't find the tables used in that view either, as you probably don't have permissions on the SYS tables that it is based on (eg SYS.user$, SYS.obj$, etc). 我打赌你也找不到该视图中使用的表,因为你可能没有它所基于的SYS表的权限(例如SYS.user $,SYS.obj $等)。

Also check to see if the "missing" table is actually a synonym: 还要检查“缺失”表是否实际上是同义词:

SELECT table_owner, table_name
  FROM all_synonyms
 WHERE table_name = 'MISSING_TABLE';

If it is not a synonym, try looking in the all_tables dictionary view for your table: 如果它不是同义词,请尝试查看表的all_tables字典视图:

SELECT owner, table_name
  FROM all_tables
 WHERE table_name = 'MISSING_TABLE';

Check the schema for the table references in the view that you can't find - it's likely to be not the current schema, but the current schema has SELECT privilege (at a minimum) on the particular table. 检查视图中找不到的表引用的架构 - 它可能不是当前架构,但当前架构在特定表上具有SELECT权限(至少)。

Once you know the schema, it should help determine if the table is actually a view in the current schema. 一旦了解了架构,它就应该有助于确定该表是否实际上是当前架构中的一个视图。 Or it could be a synonym, which exists in the current schema -- vs a public synonym is the same across all schemas, so you'd have to check the synonyms to see where it points to. 或者它可以是同义词,它存在于当前模式中 - 与所有模式中的公共同义词相同,因此您必须检查同义词以查看其指向的位置。

Is it maybe a materialized view? 这可能是物化观点吗? That's a copy of the data so it would continue to exist even if a base table was dropped. 这是数据的副本,因此即使删除了基表,它也会继续存在。

I would make sure you havent set it up by saying 我会确保你没有说出来

Create Table "TableName"
  ("ColumnName" Number(10,0))....

If you then try and reference these with the following script: 如果您尝试使用以下脚本引用这些:

Select ColumnName from TableName....

it wont work. 它不会工作。 This is because Oracle takes unquoted names like TableName and turns them into TABLENAME which doesnt exist as when you declared it with "TableName" you were in effect saying "only respond to queries with this exact capitalisation that are also in quotes " 这是因为Oracle使用不带引号的名称(如TableName)并将它们转换为TABLENAME而不存在,因为当您使用“TableName”声明它时,您实际上说“只响应具有此引号的具有此确切大小写的查询

So the following would have worked: 所以以下内容会起作用:

Select "ColumnName" from "TableName"....

But basically you should never use the case sensitive definitions because they require every query to be quoted. 但基本上你不应该使用区分大小写的定义,因为它们需要引用每个查询。

Instead do 相反

Create Table TableName
  (ColumnName Number(10,0))....

and it will respond to whatever capitalisation you feel like using when querying 并且它会响应您在查询时使用的任何大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM