简体   繁体   中英

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. 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.

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 (eg SYS.user$, SYS.obj$, etc).

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';

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.

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 "

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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