一、系統默認登錄
普通用戶: conn scott/密碼
普通管理員: conn system/密碼
超級管理員: conn sys as sysdba; 然後輸入密碼;
二、創建新用戶
create user 用戶名 identified by 密碼;
三、賦予新用戶權限
- 允許用戶登錄
grant create session to 用戶名;
- 允許新用戶連接數據庫,並創建數據庫對象
grant connect to 用戶名;
- 允許用戶使用資源的權限(例如創建表、修改表)
grant resource to 用戶名;
- 允許用戶創建表空間
grant create tablespace to 用戶名;
- 允許用戶使用表空間
grant unlimited session to 用戶名;
- 允許用戶查詢TEST表的記錄
grant select on test to 用戶名;
- 允許用戶更新test表中的記錄
grant update on test to 用戶名;
- 允許用戶增、刪、改、查test表中的記錄
grant all on test to 用戶名;
- 允許用戶刪除表
grant drop on 表名 to 用戶名;
- 更改用戶密碼
alter user 用戶名 identified by 新密碼;
- 授予對指定表特定字段的插入和修改權限,注意,只能是insert和update
grant update(id) on 表名 to 用戶名;
- 授予用戶alert任意表的權限
grant alert all table to 用戶名;
- 刪除用戶
drop user 用戶名 [cascade];
(注: 當用戶下有表或其它對象時,需要添加cascade關鍵字,級聯刪除對象)
- 允許用戶創建視圖view
grant create any view to 用戶名;
- 取消用戶操作表的權限(同義詞也不能用)
revoke all on 表名 from 用戶;
- 允許用戶創建公有同義詞
grant create public synonym to 用戶名;
- 允許用戶刪除公有同義詞
grant drop public synonym to 用戶名;
- 允許用戶創建 基於函數索引
GRANT QUERY REWRITE TO 用戶名;
四、授予其他用戶權限
- 將存儲過程的執行權限授予其他用戶
grant execute on 存儲過程名稱 to 用戶名;
grant execute on swap to public;
- 刪除存儲過程
drop procedure 存儲過程名稱;
五、查看權限
- 查看當前用戶所有權限
select * from user_ sys_ _privs;
- 查看所用用戶對錶的權限
select * from user_ tab_ privs;
六、排序
- rank() over(order by 列名) rank :並列跳空
例如:查詢每個學生的的姓名,考試的課程名和分數,並按分數進行排序,能產生並列跳空的序號
select st.stuName as 學生姓名,c.cName as 課程名稱,sc.grade as 分數,rank() over(order by sc.grade) rank from student st,course c,score sc where st.id = sc.id and c.cId = sc.cId;
- dense_rank() over(order by 列名) dense_rank :並列不跳空
例如:查詢每個學生的的姓名,考試的課程名和分數,並按分數進行排序,能產生並列跳空的序號
select st.stuName as 學生姓名,c.cName as 課程名稱,sc.grade as 分數,dense_rank() over(order by sc.grade) dense_rank from student st,course c,score sc where st.id = sc.id and c.cId = sc.cId;
- row_number() over(order by 列名) row_number :依次排序
例如:查詢每個學生的的姓名,考試的課程名和分數,並按分數進行排序,能產生並列跳空的序號
select st.stuName as 學生姓名,c.cName as 課程名稱,sc.grade as 分數,row_number() over(order by sc.grade) row_number from student st,course c,score sc where st.id = sc.id and c.cId = sc.cId;