How can I find the invisible table in oracle 11g? - oracle

There is a table named IM_RESULT_INFO. Because I can see it by SELECT * FROM IM_RESULT_INFO.
But it doesn't exist in table nor view lists in sqldeveloper. I also tested SELECT * FROM all_all_tables and SELECT * FROM dba_tables, and couldn't find the table.
In Eclipse IDE, I searched for it in whole project files, but the only code I found was SELECT ... FROM IM_RESULT_INFO.
I think it is a mixture of tables, but there's no way to analyze it. How can I find it?

It must be a synonym or a view, check the synonyms view to see what object is referenced by it:
SELECT *
FROM all_synonyms
WHERE synonym_name = 'IM_RESULT_INFO'
Or the views view:
SELECT *
FROM all_views
WHERE view_name = 'IM_RESULT_INFO'

You can check in ALL_OBJECTS if you are not sure about the type of an object. It will provide you the Types and other important details also.
For Materialized view please check ALL_MVIEWS.
SELECT *
FROM ALL_OBJECTS
WHERE OBJECT_NAME='IM_RESULT_INFO';

Related

Oracle: why I can't select from VIEW using <SCHEMA_NAME>.<VIEW_NAME>?

There are some changes on the core product on which I'm working and some tables become now views and they are not working anymore because a view cannot be referenced with the schema name in front.
For example, the below will return an error: ORA-00942: table or view does not exist
select * from my_schema.my_view;
while a direct select from the view works fine
select * from my_view;
In case of a table, both scenarios above are working fine, is just the view that doesn't accept schema_name in front.
Why is that? Are there any decent workarounds?
EDIT: the selects are executed with my_schema user
Thanks all for your help, especially #mathguy.
Basically the problem was that my_view was in fact a public synonym for my_view_r which was the actual view and being public, you cannot call it using the schema name in front like I was trying. eg:
select * from my_schema.my_view;
Maybe it will be helpful for others that are facing this issue in the future, the workaround would be to create a private synonym to the same view (my_view_r) using the schema name like below:
create synonym my_schema.my_view for my_view_r;
This is the only way to call a synonym using the schema name.
It's a grant issue.
grant all on my_view to my_schema
Make sure your schema really is the owner by running:
Select * from all_objects where object_name = 'my_view';
I have a view stvytro with owner baninst1. There is a public synonym of the same name. The following both work:
select * from STVYTRO;
select * from baninst1.stvytro;

How to get parameters properties from a stored procedure in Oracle?

I am developing an admin panel where we can determine which stored procedures and views can be called in Oracle 12c schemas, from services in our micro-services platform.
The services must know which parameters a procedure needs, and which columns a view has available, in order to call them.
I the admin panel, the creator of the procedure or view may register it, by typing in these information, like object's name, each parameter's name, length and data type.
But it would be much more elegant if the user just types the name of the object and then a SQL SELECT would retrieve a procedure's parameters properties in a table, and the same with the view's column's properties, so the panel would register those configurations automatically.
Could anybody post a query on how to achieve this? I am very new to Oracle and I don't know how to query the objects metadata.
I believe your are looking for something like this.
SELECT *
FROM SYS.DBA_PROCEDURES
WHERE OBJECT_TYPE = 'PROCEDURE'
AND OBJECT_NAME = 'xxxx'
Once you have that, you can get the parameters from something like this.
SELECT *
FROM SYS.ALL_ARGUMENTS
where object_name = 'procedure_name';
This can be used for views (I used USER_... metadata views, but you can use DBA_... depending of user grants):
SELECT A.TABLE_NAME, A.COLUMN_NAME, A.DATA_TYPE
FROM USER_TAB_COLUMNS A
INNER JOIN USER_VIEWS B ON A.TABLE_NAME = B.VIEW_NAME
/* WHERE A.TABLE_NAME = 'xxxx' */
ORDER BY TABLE_NAME, COLUMN_ID;

to check any procedure or trigger written ove table

I want to check in Oracle that if is there any Procedure or trigger written on the database table which insert the records in the table.
Please help me to find out this because I have an existing table and want to check that in that table how records would be insert.
Thanks in advance!
Dependencies between objects are maintained in the system and can be read from DBA_DEPENDENCIES (or ALL_ or USER_DEPENDENCIES).
The only limitation is that dynamic statements (eg using execute immediate) are not included because they are not known at compile time.
Please use the below code snippet. Hope this helps!
SELECT *
FROM
(SELECT owner,
name,
type,
referenced_owner,
referenced_name,
referenced_type,
owner sdev_link_owner,
name sdev_link_name,
type sdev_link_type
FROM ALL_DEPENDENCIES
WHERE REFERENCED_OWNER = 'OBJECT_OWNER'
AND referenced_name = 'TABLE_NAME'
) sub1
ORDER BY 3 ASC;

How to get list of all materialized views in oracle

How to get list of all Materialized Views.?
Try this:
SELECT *
FROM all_snapshots;
Instead of all_snapshots you can also use the all_mviews view.
select * from all_mviews;
or
select * from dba_mviews;
I never use all_snapshots before.
Here is another way to do:
select * from all_objects where OBJECT_TYPE='MATERIALIZED VIEW';
Actually ALL_MVIEWS and ALL_SNAPHOTS displays only the views the user has granted access on. To see all views in a database you must query DBA_MVIEWS or DBA_SNAPHOTS. You need special privileges or roles to query this view like the system privilege SELECT ANY DICTIONARY or the role SELECT_CATALOG_ROLE.
A similar statement holds for other ALL_ and DBA_ views.

Fully unwrap a view

In Oracle, is there an easy way to fully unwrap a view? eg: If I have a view which is made up of selects on more views, is there some way to unwrap it to just select directly on real tables?
The concept of in-line views can be used to do this. Suppose you have these 2 views:
create or replace view london_dept as
select * from dept
where loc = 'LONDON';
and
create or replace view london_mgr as
select * from emp
where job='MANAGER'
and deptno in (select deptno from london_dept);
In the second view's SQL, the reference to view london_dept can be replaced by an in-line view using the SQL from the london_dept view definition as follows:
select * from emp
where job='MANAGER'
and deptno in (select deptno from (select * from dept
where loc = 'LONDON'));
Of course, you can now see that is overly verbose and could be simplified to:
select * from emp
where job='MANAGER'
and deptno in (select deptno from dept where loc = 'LONDON');
Finally, some advice from Tom Kyte on the advantages and disadvantages of creating views of views
Get the query text of your view.
SELECT text FROM dba_views
WHERE owner = 'the-owner' AND view_name = 'the-view-name';
Parse. Search for view names within the query text.
Get the query text for each view name found. (see item 1.)
Replace each view name in the query with the related query text.
Do this recursively until there are no more views found.
Easy?
EDIT: The above instructions do not do everything required. Thinking about this a little more it gets hairy, grows legs, and maybe another arm. Finding column names, and column names that might be elaborate functions and subqueries. Bringing it all back together with the joins and clauses. The resulting query might look very ugly.
Somewhere within Oracle there may be something that is actually unwrapping a view. I don't know. I am glad I didn't use views that much in Oracle.
Up until Oracle 12.1 the correct answer is no, there is no easy way. Now, in 12.1 there is DBMS_UTILITY.EXPAND_SQL_TEXT : Expand SQL References to Views in Oracle Database 12c Release 1 (12.1) does exactly this. See the documentation of dbms_utility

Resources