oracle中的权限
一、权限
系统权限: 取得操作数据库的权限,如表的创建(目前理解好像只有create命令是系统级的)
Object权限:对数据对象object的内容进行操作的权限,如表的insert delete update select,可以将object的权限授予user或role
二、用户
(一)创建:
语法:
CREATE USER user
IDENTIFIED {BY password | EXTERNALLY|GLOBALLY AS external name}
[ DEFAULT TABLESPACE tablespace ]
[ TEMPORARY TABLESPACE tablespace ]
[ QUOTA {integer [K | M ] | UNLIMITED } ON tablespace
[ QUOTA {integer [K | M ] | UNLIMITED } ON tablespace ]...]
[ PASSWORD EXPIRE ]
[ ACCOUNT { LOCK | UNLOCK }]
[ PROFILE { profile | DEFAULT }]
例子:
SYS>create user user_a identified by user_a
SYS>alter user user_a account unlock;
(二) 删除:
SYS> drop user user_a cascade;
(三)修改密码
SYS>alter user app identified by app123;
三、给用户授予系统权限
(1) 语法:
GRANT privilege [, privilege...]
TO user [, user| role, PUBLIC...];
例子:
SYS>grant create session to user_a;//此时user_a可以与数据库进行对话了
SYS> grant create table to user_a;//授权create table的权利
SYS> alter user user_a quota 5m on users;//user_a可以用数据库中5M空间 5m可以用unlimited替换,表示没空间限制
(2)系统权限WITH ADMIN OPTION
用户只有具有了admin option后才可以将系统权限授予其他用户,
sys将系统权限如create table授予user_a,而user_a将权限再授予user_b
create table
sys-->user_a--->user_b
当sys回收revoke权限时,user_b中还create table权限,user_b可以将create table的权限重新给user_b;
例子:
SYS>grant create table to user_a with admin option;
user_a>grant create table to user_b with admin option;
user_a>create table t1(id int);//OK
user_b>create table t1(id int);//OK
SYS>revoke create table from user_a;
user_a>create table t2(id int);//fail user_b权限已被回收
user_b>create table t2(id int);//OK user_a权限没有被级联回收
user_b>grant create table to user_a with admin option;// user_b具有asmin option 可以将系统权限授予其他用户
user_a>create table t2(id int);//OK
四、Object权限privilege
(一)创建
语法:
GRANT object_priv [(columns)]
ON object
TO {user|role|PUBLIC}
[WITH GRANT OPTION]
[WITH ADMIN OPTION];
例子:
grant select on user_a.t1 to user_b;
(二)回收
语法:
REVOKE {privilege [, privilege...]|ALL}
ON object
FROM {user[, user...]|role|PUBLIC};
例子:
REVOKE select,insert ON departments FROM scott;
五、 角色(role)
角色可以看做是带有一堆权限的抽象用户
(一)创建
sys>create role role_test identified by test;
(二)授权
grant role_test to scott
(三)删除
drop role role_test;
(四)回收
sys>revoke role_test from scott;
六、涉及到的数据字典
用户:
USER_ROLE_PRIVS
USER_SYS_PRIVS
session:
session_privs
session_roles
dba:
dba_roles
dba_role_privs
role:
role_role_privs
role_sys_privs
role_tab_privs
练习见附件