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

发布于 2024-10-01 08:23:39 字数 174 浏览 1 评论 0原文

我有一个 Oracle 视图,它使用的表在任何地方都找不到。但是,我仍然可以查询视图,我原以为这是不可能的。

视图内容是否从表仍然存在时就缓存在某处,或者我只是没有足够努力地查找表?

需要明确的是:我查看了 ALL_TABLES 和 ALL_OBJECTS,并且该表(或其他任何内容)都没有出现在其中。

I have an Oracle view that uses a table that I cannot find anywhere. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泅渡 2024-10-08 08:23:39

这是很有可能的。在视图上授予 select 不会在基础表上授予 select。这允许我创建一个视图,该视图公开表中的几列,但我不希望您看到全部这些列。您必须有权访问该表才能使其显示在 ALL_TABLES 视图中。如果它确实是一个表,您应该能够在 DBA_TABLES 视图中找到它(假设您有权访问 DBA_TABLES 视图),该视图包含所有内容,而不仅仅是您的用户有权访问的表。

事实上,ALL_TABLES 视图就是这种情况的完美示例。我敢打赌您也找不到该视图中使用的表,因为您可能没有它所基于的 SYS 表的权限(例如 SYS.user$、SYS.obj$ 等)。

This is very possible.. Granting select on a view does not grant select on the underlying tables. 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. 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.

In fact, the ALL_TABLES view is a perfect example of this situtation. 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 (e.g. SYS.user$, SYS.obj$, etc).

岁月静好 2024-10-08 08:23:39

还要检查“丢失”的表是否实际上是同义词:

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

如果它不是同义词,请尝试在 all_tables 字典视图中查找您的表:

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

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:

SELECT owner, table_name
  FROM all_tables
 WHERE table_name = 'MISSING_TABLE';
我很坚强 2024-10-08 08:23:39

这可能是一个物化视图吗?这是数据的副本,因此即使删除基表,它也会继续存在。

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.

猛虎独行 2024-10-08 08:23:39

检查视图中找不到的表引用的架构 - 它可能不是当前架构,但当前架构对特定表具有(至少)SELECT 权限。

了解架构后,它应该有助于确定该表是否实际上是当前架构中的视图。或者它可能是一个同义词,存在于当前模式中 - 而公共同义词在所有模式中都是相同的,因此您必须检查同义词以查看它指向的位置。

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.

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.

清风挽心 2024-10-08 08:23:39

我会确保您没有设置它,

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

如果您尝试使用以下脚本引用它们:

Select ColumnName from TableName....

它将不起作用。这是因为Oracle采用不带引号的名称(例如TableName)并将它们转换为TABLENAME,而当您使用“TableName”声明它时,该名称并不存在,您实际上是在说“仅响应具有这种精确大写且也在引号中的查询”强>“

所以以下内容会起作用:

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

但基本上你永远不应该使用 区分大小写的定义,因为它们要求每个查询都被引用。

相反

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

,它会响应您在查询时想要使用的任何大小写

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"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文