问题
I am new db.
Lets say I have created a view with force.
So how can I get know whether the view created is invalid or not?
I mean are there any queries from which I can get to know the validity status of the view?
Thanks.
回答1:
You can use Oracle dictionary view user_objects
:
select object_name, status from user_objects
where object_type = 'VIEW' and object_name = 'YOUR_VIEW';
If the table on which the view is based is altered for any reason, you may have to recompile the view. For example, if a table’s structure is altered, such as by a change to a column’s datatype, or perhaps if a column is dropped from the table altogether - a column that is used by the view — then it may change the status of the view to 'INVALID'.
Also note that there are there versions of "all objects" view:
USER_OBJECTS
- all objects owned by a current user;ALL_OBJECTS
- all objects on which a current user has any privileges;DBA_OBJECTS
- all database objects (you would need special privileges to access this view)
ALL_ and DBA_ versions have an additional column OWNER
containing the owner of the object.
These "naming rules" are applied to the different Oracle dictionary views: [USER_ | ALL_ | DBA_] [INDEXES | TABLES | VIEWS | etc]
回答2:
Maybe this helps:
SELECT object_name,
status
FROM user_objects
WHERE object_type = 'VIEW';
or (for views in all schemas)
SELECT owner,
object_name,
status
FROM all_objects
WHERE object_type = 'VIEW';
回答3:
Apart from checking the status about that new view in the dictionary, you can do:
select 1 from OWNER.MY_NEWLY_CREATED_VIEW;
or
select count(*) from OWNER.MY_NEWLY_CREATED_VIEW;
Whatever the statement of your new view, from that feedback you know it works or not.
来源:https://stackoverflow.com/questions/26967458/how-to-know-whether-the-created-view-is-valid-or-not