Oracle基础学习5-- Oracle权限之”角色”

  不论什么与权限相关的东西都少不了”角色”的概念,Java如此,.Net如此,Oracle当然也不例外。

  角色事实上就是权限的集合,将多个权限打包到一个角色中,这样每一个角色有特定的权限。当须要给某个对象赋予某种权限时,就找到具有对应权限的角色,然后将它加到这个集合其中。以下就简单看看Oracle中角色的运用。

  上篇文章讲到,为了给多用户授予各种权限,我们用到了“权限传递”来取代给用户们一个个授权,简化了授权过程。但这样的方式较之用“角色”方式授权还是有非常多不便。

  事实上“角色”与普通用户无太大区别,只是一个是“类”一个是“对象”而已。所以对“角色”的操作与对“普通用户”的操作基本同样,例如以下:

  首先用系统用户“sys”连接到Oracle,并创建“角色”myrole:

  

 

  然后为角色—myrole授权:

  

  创建一个新用户“wangwu”,然后将角色-myrole授权给wangwu:

  

  这样用户“wangwu”就拥有了myrole(多种权限的集合)中的全部权限。我们还能够吧myrole这个权限集合授权给随意的用户,这样,权限授予起来就方便多了。

  注:因为角色范围太大,一旦为角色赋予了某项权限,那么它以下全部的用户都将拥有此权限,所以有些大的“权限”不能直接授予给角色,比方曾经的unlimited tablespace就不能授予角色,只是到Oracle11g,试了一下能够授予给角色了:

  

  Oracle就说到这里,以下是网上看到的,比較全的Oracle经常使用操作:

oracle用户的权限管理
 
----sys Login------------
 1 创建表空间及暂时表空间 
create tablespace csdn1 datafile 'csdn1' size 30m autoextend on; 
create temporary tablespace csdn2 tempfile 'csdn2' size 30m autoextend on;   
2 创建用户指定表空间及暂时表空间 
create user csdn identified by csdn default tablespace csdn1 temporary tablespace csdn2;   
3 授予用户各种权利 
grant create session to csdn; 
grant unlimited tablespace to csdn; 
grant connect to csdn; grant resource to csdn; 
grant create sequence to csdn; grant create table to csdn;   
4 查询当前用户的权限 
select * from user_sys_privs;   
5 撤销用户各种权限 
revoke create table from csdn; revoke create session from csdn; 
revoke create sequence to csdn; revoke resource to csdn; 
revoke connect to csdn; revoke unlimited tablespace to csdn;   
6 通过角色来赋予用户各种权限 
create user root identified by root default tablespace csdn1 temporary tablespace csdn2; 
create role role1; grant create table to role1; 
grant create session to role1; 
grant connect to role1; 
grant resource to role1; 
grant create sequence to role1;   
(1) 将角色赋予给用户 grant role1 to root;   
(2) 删除角色 drop role role1;   
7 序列 
create sequence xulie 
minvalue 1 
maxvalue 222222 
start with 1 increment by 1 
nocache 
nocycle   

----csdn Login--------- 

1 创建表 
drop table tb_book; 
create table tb_book ( book_id int primary key not null, book_name varchar(32) not null, book_des varchar(100) not null);   
2 通过序列来插入数据 
insert into tb_book(book_id,book_name,book_des) values(xulie.nextval,'计算机科学与技术','计算机'); 
insert into tb_book(book_id,book_name,book_des) values(xulie.nextval,'信息管理技术','信管'); 
insert into tb_book(book_id,book_name,book_des) values(xulie.nextval,'专业英语','外语'); 
insert into tb_book(book_id,book_name,book_des) values(xulie.nextval,'土木project建设','土木'); 
select * from tb_book;   
3 创建学生表 
create table tb_student ( stu_id int primary key not null, stu_name varchar(32) not null, stu_sex char(2) not null check(stu_sex in('男','女')), stu_age int not null);   
4 更改表的别名 
rename tb_student to tb_stu;   
5 创建借书记录表 
create table tb_borrow ( borrow_id int primary key not null, stu_id int not null, book_id int not null); rename tb_borrow to tb_j; alter table tb_j add constraint b_b foreign key(book_id) references tb_book(book_id); alter table tb_j add constraint b_s foreign key(stu_id) references tb_stu(stu_id);       
6 查询语句 列出全部借书的记录号 书名 借书的人名 
select j.borrow_id,s.stu_name,b.book_name from tb_stu s,tb_book b,tb_j j where s.stu_id=j.stu_id and b.book_id=j.book_id;   
列出同一个专业 可是借了不同一本书的学生 
select s.zhuanye,s.stu_name,b.book_name from tb_book b,tb_stu s order by s.zhuanye,b.book_name;   
7 数值函数 
select ceil(13.2) from tb_stu; --向上取整 
select floor(12.9) from tb_stu;--向下取整 
select power(9,19) from tb_stu;--9的19次方 
select sqrt(8) from tb_stu;    --8的平方根 
select sign(-2) from tb_stu;   --正数返1 负数返-1 0返0 
select trunc(12.232323123,5) from tb_stu;--取5位小数 
select round(1232.343,2) from tb_stu;--小数位为2 四舍五入 
select exp(3) from tb_stu; --求指数 
select mod(12,8) from tb_stu; --求余数 
select ln(10) from tb_stu;--自然对数 
select log(10,100) from tb_stu;--以10为底 100的对数 
select vsize(1010) from tb_stu;--返回1010所占空间的大小    
8 经常使用的函数 
select initcap(stu_name) from tb_stu;--首字符转换成大写 
select stu_name,instr(stu_name,'s') from tb_stu;--查找s在stu_name中的位置 返回对应的值(0 n) 
select length(stu_name) from tb_stu;--返回长度 
select upper(stu_name) from tb_stu;--换大写 
select lower(stu_name) from tb_stu;--换小写 
select lpad(stu_name,11,'Hello') from tb_stu;--长度不够则在左边填充Hello 直到够11 


 

 

原文地址:https://www.cnblogs.com/mfrbuaa/p/3826974.html