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

后端 未结 5 1078
攒了一身酷
攒了一身酷 2021-01-31 19:59

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

5条回答
  •  盖世英雄少女心
    2021-01-31 20:26

    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.

提交回复
热议问题