2 select ename,sal from emp;
View created
SQL> grant v_test to test;
grant v_test to test
ORA-01919: 角色 'V_TEST' 不存在
SQL> grant select on v_test to test;
Grant succeeded
SQL> select * from v_test;
ENAME SAL
---------- ---------
SMITH 1800.00
ALLEN 1600.00
WARD 1250.00
JONES 2975.00
MARTIN 1250.00
BLAKE 2850.00
CLARK 2450.00
SCOTT 3000.00
KING 5000.00
TURNER 1500.00
ADAMS 1100.00
JAMES 950.00
FORD 3000.00
MILLER 1300.00
14 rows selected
授权test用户只能修改sal字段。
SQL> grant update(sal) on emp to test;
Grant succeeded
授权test用户只能插入empno和empname字段。
SQL> grant insert(empno,ename) on emp to test;
Grant succeeded
6、收回用户对应权限。(用scott用户登录收回上面的v_test查询的权限和修改sal字段权限和插入empno,ename的权限)
SQL> CONN SCOTT/SCOTT
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as scott
SQL> REVOKE SELECT ON V_TEST FROM TEST;
Revoke succeeded
SQL> REVOKE UPDATE(SAL) ON EMP FROM TEST;
REVOKE UPDATE(SAL) ON EMP FROM TEST
ORA-01750: UPDATE/REFERENCES 只能从整个表而不能按列 REVOKE
SQL> REVOKE UPDATE ON EMP FROM TEST;
Revoke succeeded
SQL> REVOKE INSERT ON EMP FROM TEST;
Revoke succeeded
注:注意上面的错误提示不能对表的某列revoke只能对整个表revoke。
7、权限的传递。(用SCOTT用户登录授权test用户select查询v_test的权限并允许test用户拥有把此权限传递授予test1用户)
SQL> CONN SCOTT/SCOTT
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as scott
SQL> GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTIONS;
GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTIONS
ORA-00994: 缺失 OPTION 关键字
SQL> GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTION;
Grant succeeded
SQL> CONN TEST/TEST
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as test
SQL> GRANT SELECT ON V_TEST TO TEST1;
GRANT SELECT ON V_TEST TO TEST1
ORA-00942: 表或视图不存在
SQL> GRANT SELECT ON SCOTT.V_TEST TO TEST1;
Grant succeeded
注:(1)权限的传递只需要在授权时加上with grant option就能让被授权的用户将些权限授予其他用户。 (2)如果授权的是
系统权限(上面操作的都是对象权限)传递给其他人时只需要加上with admin option。 (3)
此时如果scott用户把test的查询v_test权限收回将一同把test1的查询v_test权限收回。
8、使用profile管理用户口令。 profile 是口令限制,资料限制的命令集合,当建立数据库时,ORACLE会自动建立名称为default的profile,当建立用记没有指定profile选项,寻oracle会将default分配给用户。 (设定test用户最多只能尝试2次登录,锁定时间为3天)
SQL> conn system/orcl
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as system
SQL> create profile lock_account limit failed_login_attempts 2 password_lock_time 3;
Profile created
SQL> alter user test profile lock_account;
User altered
通过下面对用户强制解锁
SQL> alter user test account unlock;
User altered
(设定用户定期修改密码,每隔10天修改自己的密码宽限期为3天)
SQL> create profile remind_account limit password_life_time 10 password_grace_time 3;
Profile created
SQL> alter user test profile remind_account;
User altered
删除直接drop profile remind_account;