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

后端 未结 5 1077
攒了一身酷
攒了一身酷 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:08

    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;
    

提交回复
热议问题