(转载)Oracle创建用户并给用户授权查询指定表或视图的权限
原文地址:http://blog.sina.com.cn/s/blog_4509ce1f0100v8vd.html
用DNINMSV31账户登录数据库进行如下操作:
CREATE USER NORTHBOUND IDENTIFIED BY NORTHBOUND
DEFAULT TABLESPACE "TBS_DNINMSV31"
TEMPORARY TABLESPACE "TEMP2"
QUOTA UNLIMITED ON "TBS_DNINMSV31";
GRANT "CONNECT" TO NORTHBOUND;
ALTER USER NORTHBOUND DEFAULT ROLE NONE;
GRANT CREATE SESSION TO NORTHBOUND;
GRANT SELECT ON "DNINMSV31"."V_DNDEVICE" TO NORTHBOUND;
GRANT SELECT ON "DNINMSV31"."V_DNSUBNE" TO NORTHBOUND;
GRANT SELECT ON "DNINMSV31"."V_DNPACKAGE" TO NORTHBOUND;
GRANT SELECT ON "DNINMSV31"."V_DNPORT" TO NORTHBOUND;
【注】:在用NORTHBOUND登录后查询的时候要在视图前加上DNINMSV31,否则会报表或视图不存在。
例如:
select * from DNINMSV31.V_DNDEVICE; --可以正常执行
select * from DNINMSV31.TB_DEVICE where rownum<5; --执行的时候会报表或视图不存在
--------------------------------------------------------------------------------------------------
GRANT debug any procedure, debug connect session TO hnckb;
grant select on sys.dba_pending_transactions to hnckb;
grant CREATE VIEW,CREATE JOB,CREATE SYNONYM to hnckb;
grant CONNECT,RESOURCE to hnckb;
1.标准角色
CONNECT
RESOURCE
2.系统权限
CREATE VIEW
CREATE DATABASE LINK
CREATE JOB
CREATE SYNONYM
UNLIMITED TABLESPACE
更改定额
命令:ALTER USER 名称 QUOTA 0 ON 表空间名
ALTER USER 名字 QUOTA (数值)K|M|UNLIMITED ON 表空间名;
使用方法:
A、控制用户数据增长
B、当用户拥有一定的数据,而管理员不想让他在增加新的数据的时候。
C、当将用户定额设为零的时候,用户不能创建新的数据,但原有数据仍可访问。
3.对象权限
DBA_PENDING_TRANSACTIONS (SELECT) — XA事务支持
grant select on sys.dba_pending_transactions to user;
4.建议开放
DEBUG CONNECT SESSION — 调试存储过程
例如:
GRANT debug any procedure, debug connect session TO hr;
Oracle创建表空间、创建用户、授权、授权对象的访问以及查看权限
1.创建临时表空间
Oracle临时表空间主要用来做查询和存放一些缓冲区数据。临时表空间消耗的主要原因是需要对查询的中间结
果进行排序。
临时表空间的主要作用:
索引create或rebuild
Order by 或 group by
Distinct 操作
Union 或 intersect 或 minus
Sort-merge joins
CREATE TEMPORARY TABLESPACE “TEST_TEMP”
TEMPFILE ‘D:ORACLEPRODUCT10.2.0ORADATAGISTEST_DATA.ora’
SIZE 20M
AUTOEXTEND ON
NEXT 32M MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL;
2.创建用户表空间
CREATE TABLESPACE “TEST_DATA”
LOGGING
DATAFILE ‘D:ORACLEPRODUCT10.2.0ORADATAGISTEST_DATA.ora’
SIZE 20M
AUTOEXTEND ON
NEXT 32M MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL;
3.创建用户并设置其表空间
username:usertest
password:userpwd
CREATE USER usertest IDENTIFIED BY userpwd
DEFAULT TABLESPACE TEST_DATA
TEMPORARY TABLESPACE TEST_TEMP;
4.给用户授权
GRANT
CREATE SESSION, CREATE ANY TABLE, CREATE ANY VIEW ,CREATE ANY INDEX, CREATE ANY PROCEDURE,
ALTER ANY TABLE, ALTER ANY PROCEDURE,
DROP ANY TABLE, DROP ANY VIEW, DROP ANY INDEX, DROP ANY PROCEDURE,
SELECT ANY TABLE, INSERT ANY TABLE, UPDATE ANY TABLE, DELETE ANY TABLE
TO username;
首先授权用户testuser两个基本的角色权限
CONNECT角色: –是授予最终用户的典型权利,最基本的
CREATE SESSION –建立会话
RESOURCE角色: –是授予开发人员的
CREATE CLUSTER –建立聚簇
CREATE PROCEDURE –建立过程
CREATE SEQUENCE –建立序列
CREATE TABLE –建表
CREATE TRIGGER –建立触发器
CREATE TYPE –建立类型
CREATE OPERATOR –创建操作者
CREATE INDEXTYPE –创建索引类型
CREATE TABLE –创建表
授权角色给用户的sql语句:
GRANT role TO username;
5.查看用户权限
查看所有用户
SELECT * FROM DBA_USERS;
SELECT * FROM ALL_USERS;
SELECT * FROM USER_USERS;
查看用户系统权限
SELECT * FROM DBA_SYS_PRIVS;
SELECT * FROM USER_SYS_PRIVS;
查看用户对象或角色权限
SELECT * FROM DBA_TAB_PRIVS;
SELECT * FROM ALL_TAB_PRIVS;
SELECT * FROM USER_TAB_PRIVS;
查看所有角色
SELECT * FROM DBA_ROLES;
查看用户或角色所拥有的角色
SELECT * FROM DBA_ROLE_PRIVS;
SELECT * FROM USER_ROLE_PRIVS;
遇到no privileges on tablespace ‘tablespace ‘
alter user userquota 10M[unlimited] on tablespace;