Reference a table in other schema omiting schema name

孤街醉人 提交于 2019-12-18 09:41:33

问题


If I have a table sch1.tab1 is it possible to call it from schema/user sch2 just with select * from tab1 (assume that we have all the privilegies)?

I am aware that in postgresql you can set the search path where db would look for tables which enables you to omit the schema when you are referencing a table but I do not know if this exists in oracle.

Thank you.


回答1:


You can create a synonym, but you'd have to make one for each table you wanted to access; from sch2:

create synonym tab1 for sch1.tab1;

A more general method is to switch your current schema:

alter session set current_schema = 'SCH1';

You're still connected with your original user account and only have those privileges still, but you don't have to qualify objects in that schema any more. But now you would have to qualify any of your own tables (back in sch2), if you have objects in both schemas.



来源:https://stackoverflow.com/questions/20531747/reference-a-table-in-other-schema-omiting-schema-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!