How to get the created / last DDL time for an Oracle synonym? - oracle

SQL Developer shows the creation and last DDL time for a public synonym in a table:
CREATED 15-AUG-09
LAST_DDL_TIME 15-AUG-09
OWNER PUBLIC
SYNONYM_NAME ISEMPTY
TABLE_OWNER MDSYS
TABLE_NAME OGC_ISEMPTY
DB_LINK (null)
How can I get the same information via a SQL query?
select * from all_synonyms where synonym_name = 'ISEMPTY'
does not get the created/last ddl dates.
More generally, is there a good way to see the queries that sql developer uses to display the data it displays (when you do not have access to a profiler)?
Thanks

You need the ALL_OBJECTS system view:
select *
from all_objects
where owner = 'OWNER_NAME'
and object_name = 'ISEMPTY'
and object_type = 'SYNONYM'

Related

Why can't table be listed in oracle db?

in oracle database on linux server;
desc table_x; => getting data
select * from table_x; => getting data
SELECT table_name from all_tables; => it is not in the list
How can I get this table to appear in the list?
Thanks.
Looks like it isn't a table that is contained in all_tables. What is it, then?
Might be a synonym, so try
select * from all_synonyms where synonym_name = 'TABLE_X';
Or, a view:
select * From all_views where view_name = 'TABLE_X';

grant SELECT access to v$session to other users

I want to grant SELECT access to v$session to other users in an Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
but when I run this query:
SELECT owner, object_type FROM dba_objects WHERE object_name = 'V$SESSION';
I got this error:
00942. 00000 - "table or view does not exist"
Oracle v$ views are named V_$VIEWNAME and they have synonyms in format V$VIEWNAME and you can’t give privilege on a synonym. If you want to give permission to a V$ view you must give it like below
SQL> grant select on v_$session to hr;
We also needed a regular user without access to v$session to cleanup sessions. A function will execute with the privileges of the owning schema, so if you create a function as the user having access to V$SESSION you can execute it from the user not having the required privilege.
For example, IFH_OWNER has access to v$session, user id854812 doesn't:
As id854812:
select count(*) from v$session
ORA-00942: table or view does not exist
As IFH_OWNER:
select count(*) from v$session
56
create or replace function getSessionCount return int
as
vCnt int;
begin
select count(*) into vCnt from v$session;
return( vCnt);
end;
select getSessionCount from dual;
56
grant execute on getSessionCount to id854812;
As id854812:
select ifh_owner.getSessionCount from dual;
56

Oracle query to get latest table or stored procedure schema change?

I'm trying to write a query to get the latest schema changes to a table or stored procedure on Oracle.
This is how to do this on Sybase:
select top 10 name from sysobjects where type = 'U' order by crdate desc
(I accept that this is built on created date and not modified date - I'd appreciate anyone who can show me how the modified date works in Sybase for tables but what I'm looking for is Oracle schema change date right now).
My question is: What is the Oracle query to get latest table or stored procedure schema change?
select * from
(SELECT * FROM user_objects ORDER BY last_ddl_time DESC)
where rownum <= 10;
user_objects contains all the objects owned by the current user (= current schema objects)
all_objects contains all the objects on which the user has any privileges
dba_objects contains all the DB objects (requires some special privileges to access).
all_ and dba_ have the additional column owner
3rd party edit
You may want to read does-rebuilding-an-index-update-the-last-ddl-time ...
From ROWNUM Pseudocolumn
For each row returned by a query, the ROWNUM pseudocolumn returns a
number indicating the order in which Oracle selects the row from a
table or set of joined rows. The first row selected has a ROWNUM of 1,
the second has 2, and so on.
You can use ROWNUM to limit the number of rows returned by a query,...
If you want to be specific about the table or procedure, you can limit like below
with 11g database
select * from
(SELECT * FROM user_objects where OBJECT_TYPE in ('TABLE','PROCEDURE') ORDER BY last_ddl_time DESC)
where rownum <= 10;
The above will give the latest changed objects either in table or procedure.
whereas in 12c database no need to use subquery
SELECT * FROM user_objects
where OBJECT_TYPE in ('TABLE','PROCEDURE')
ORDER BY last_ddl_time DESC
FETCH FIRST 10 ROWS ONLY;

How do you query for blank schemas?

I'm trying to locate blank schemas within my oracle server.
I've tried using DBA_TAB_COLS, but no success. Eg:
select * from
(
select OWNER, COUNT(distinct(TABLE_NAME)) as TABLE_COUNT
from DBA_TAB_COLS
group by OWNER
)
where TABLE_COUNT = 0
Is there a way to query for a list of blank schemas?
If "blank schema" means a schema that does not own any tables
SELECT username
FROM dba_users u
WHERE NOT EXISTS(
SELECT 1
FROM dba_tables t
WHERE t.owner = u.username
);
If you want to look for schemas that own no object, rather than schemas that own no tables, you'd use dba_objects in the subquery rather than dba_tables. For either of these, though, you'd need to have privileges to query the dba_* objects.

How can I find the OWNER of an object in Oracle?

I want to find the foreign keys of a table but there may be more than one user / schema with a table with the same name. How can I find the one that the currently logged user is seeing? Is there a function that gives its owner? What if there are public synonyms?
You can query the ALL_OBJECTS view:
select owner
, object_name
, object_type
from ALL_OBJECTS
where object_name = 'FOO'
To find synonyms:
select *
from ALL_SYNONYMS
where synonym_name = 'FOO'
Just to clarify, if a user user's SQL statement references an object name with no schema qualification (e.g. 'FOO'), Oracle FIRST checks the user's schema for an object of that name (including synonyms in that user's schema). If Oracle can't resolve the reference from the user's schema, Oracle then checks for a public synonym.
If you are looking specifically for constraints on a particular table_name:
select c.*
from all_constraints c
where c.table_name = 'FOO'
union all
select cs.*
from all_constraints cs
join all_synonyms s
on (s.table_name = cs.table_name
and s.table_owner = cs.owner
and s.synonym_name = 'FOO'
)
HTH
-- addendum:
If your user is granted access to the DBA_ views (e.g. if your user has been granted SELECT_CATALOG_ROLE), you can substitute 'DBA_' in place of 'ALL_' in the preceding SQL examples. The ALL_x views only show objects which you have been granted privileges. The DBA_x views will show all database objects, whether you have privileges on them or not.
I found this question as the top result while Googling how to find the owner of a table in Oracle, so I thought that I would contribute a table specific answer for others' convenience.
To find the owner of a specific table in an Oracle DB, use the following query:
select owner from ALL_TABLES where TABLE_NAME ='<MY-TABLE-NAME>';
Interesting question - I don't think there's any Oracle function that does this (almost like a "which" command in Unix), but you can get the resolution order for the name by:
select * from
(
select object_name objname, object_type, 'my object' details, 1 resolveOrder
from user_objects
where object_type not like 'SYNONYM'
union all
select synonym_name obj , 'my synonym', table_owner||'.'||table_name, 2 resolveOrder
from user_synonyms
union all
select synonym_name obj , 'public synonym', table_owner||'.'||table_name, 3 resolveOrder
from all_synonyms where owner = 'PUBLIC'
)
where objname like upper('&objOfInterest')
Oracle views like ALL_TABLES and ALL_CONSTRAINTS have an owner column, which you can use to restrict your query. There are also variants of these tables beginning with USER instead of ALL, which only list objects which can be accessed by the current user.
One of these views should help to solve your problem. They always worked fine for me for similar problems.
To find the name of the current user within an Oracle session, use the USER function.
Note that the owner of the constraint, the owner of the table containing the foreign key, and the owner of the referenced table may all be different. It sounds like it’s the table owner you’re interested in, in which case this should be close to what you want:
select Constraint_Name
from All_Constraints
where Table_Name = 'WHICHEVER_TABLE'
and Constraint_Type = 'R' and Owner = User;
It is like #entpnerd said, but I suggest you to use upper() clause:
select *
from ALL_TABLES
where upper(TABLE_NAME) = upper('<table_name>')

Resources