如何在没有sys权限的情况下在oracle中创建别名

How to create aliases in oracle without sys privilages

我正在尝试为我拥有 select 权限的 sh 模式中的表创建别名,我的模式是 cs1761xx。我正在尝试在这些表上获得 select 特权,而不必在前面加上 sh.xxxx。我该怎么做呢?我再次使用的模式是 cs1761xx,而且我不应该创建新用户。

    SQL> create synonym customers1 for sh.customers;
    create synonym customers1 for sh.customers
    *
    ERROR at line 1:
    ORA-01031: insufficient privileges

如果您的 DBA 不授予您创建同义词所需的权限,并且这是指 'aliases' 而不是专门针对同义词的课程作业,您只需要查询表即可。 .. 那么另一种选择是创建一个视图:

create view customers as select * from sh.customers;

当然,还要假设您有权限这样做。不过,这有点延伸了 'alias' 的含义。 (您也可以插入、更新和删除,但需要一个替代触发器;但这似乎超出了范围)。

使用 alter session set current_schema = sh; 以避免必须在模式名称前加上:

SQL> select count(*) from customers;
select count(*) from customers
                     *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> alter session set current_schema = sh;

Session altered.

SQL> select count(*) from customers;

  COUNT(*)
----------
         0

SQL>