一、需求
數據庫有個表car,需要為這個表建立一個視圖view_car,並新建一個用戶user01,賦予查詢這個視圖的權限
二、實施步驟
1、以管理員clgl登陸數據庫,新建視圖view_car:
create or replace view view_car as select * from CAR;
2、新建用戶user01
create user user01
identified by "123456";
3、授予用戶user01權限
grant select on view_car_runtime_b to user01; //查詢視圖權限
grant connect to user01; //連接數據庫權限
grant create synonym to user01; //新建同義詞權限
4、以用戶user01登陸數據庫,可以訪問到視圖view_car的信息
select * from clgl.view_car; //查詢視圖view_car的信息,由於每次都需要加上用戶前綴clgl.,十分不方便,因此設置一個同義詞方便查詢
5、為視圖clgl.view_car新建一個別名car
create synonym car for clgl.view_car; //設置clgl.view_car的別名為car
select * from car; //用戶可以直接輸入car查詢數據
6、以clgl登陸數據庫,設置用戶user01的允許訪問會話數
alter system set resource_limit=true scope=both sid='*'; //使用resource_limit及profile限制用戶連接
create profile user01_profile limit SESSIONS_PER_USER 1 FAILED_LOGIN_ATTEMPTS unlimited; //新建一個user profile:user01_profile
alter user user01 profile user01_profile; //更改用戶user01的profile為user01_profile
alter profile user01_profile limit SESSIONS_PER_USER 2; //限定用戶user01的連接數為2
當user01的訪問連接數超過三個時,會提示錯誤:ora-02391:exceeded simultaneous sessions_per_user limit