Oracle 将用户 A 的权限授予用户 B

Oracle grant Privilege User A to User B


    I create user A and B with system admin
    -- CREATE USER1 SQL
    CREATE USER USERA IDENTIFIED BY 123456 ;
    GRANT CREATE SESSION TO USERA;
    CREATE USER USERB IDENTIFIED BY 123456 ;
    GRANT CREATE SESSION TO USERB;

    and set Privileges to USERA
    -- SYSTEM PRIVILEGES USERA
    GRANT CREATE TABLE TO USERA;
    GRANT DELETE ANY TABLE TO USERA;
    GRANT GRANT ANY PRIVILEGE TO USERA;

    and create table by USERA

    CREATE TABLE tableA 
    (ID VARCHAR2(5)
    , DATA VARCHAR2(20) );

    and create Privileges to USERB by USERA set select tableA
    GRANT SELECT ON tableA to USERB;

    but USERB can't select tableA 
    ERROR:ORA-00942: table or view does not exist

    How do I solve the problem?

如果您没有为 table 指定所有者,Oracle 将假定所有者是当前用户。

select * from usera.tablea;

为避免此问题,通常建议创建一个本地同义词(由 userb 拥有):

create synonym userb.tablea for usera.tablea;

现在,userb 可以查询 table:

select * from tablea;