权限是实时起作用的,role要在重新登陆后起作用
测试:
先看权限的情况
session1:
system@O9I.US.ORACLE.COM> create user testpriv identified by testpriv;
用户已创建
system@O9I.US.ORACLE.COM> grant connect, resource to testpriv;
授权成功。
session2:
system@O9I.US.ORACLE.COM> connect testpriv/testpriv
已连接。
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在
session1:
system@O9I.US.ORACLE.COM> grant select on scott.emp to testpriv;
授权成功。
session2:
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
COUNT(*)
----------
14
session1:
system@O9I.US.ORACLE.COM> revoke select on scott.emp from testpriv;
撤销成功。
session2:
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在
可见直接授权是立即生效的, 不需要用户重新登陆.
下面看看通过角色授权的情况:
session1:
system@O9I.US.ORACLE.COM> create role testprivrole;
角色已创建
system@O9I.US.ORACLE.COM> grant select on scott.emp to testprivrole;
授权成功。
system@O9I.US.ORACLE.COM> grant testprivrole to testpriv;
授权成功。
session2:
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在
可见,通过角色授权并未立即生效, 我们将session2断开重新登陆
system@O9I.US.ORACLE.COM> disconnect
从Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production中断开
system@O9I.US.ORACLE.COM> connect testpriv/testpriv
已连接。
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
COUNT(*)
----------
14
重新登陆后,通过角色授权生效了, 那么撤销授权呢?
session1:
system@O9I.US.ORACLE.COM> revoke testprivrole from testpriv;
撤销成功。
session2:
system@O9I.US.ORACLE.COM> select count(*) from scott.emp;
COUNT(*)
----------
14
可见,即使是撤销角色,也要等到下次登陆才能生效。
再来看看,如果撤销对角色的授权的情况:
session1:
system@O9I.US.ORACLE.COM> revoke select on scott.emp from testprivrole;
撤销成功。
session2:
Not connected> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在
结论: 授予权限(privileges)总是立即生效的(无论授予用户还是角色),给用户授予角色要等到下次登陆才能生效。