任何與權限相關的東西都少不了”角色”的概念,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,'土木工程建設','土木');
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