oracle学习记录之授权(2)
2013-01-04 22:14
225 查看
oracle学习记录,授权,新的需求:把某用户的所有表的查询权限授给另一个用户。用oracle学习记录之授权(1)逐个表授权有点耗时费力。
思路:用所有表名构造grant语句,复制粘贴执行,省事。练习过程如下:
一、准备
sys用户连接数据库:
connect sys/oracle as sysdba;
建立test1、test2用户:
create user test1 identified by 123;
create user test2 identified by 123;
授予dba角色给test1:
grant dba to test1;
dba角色权限太大,收回dba角色:
revoke dba from test1;
授予test1、test2用户创建会话的权限:
grant create session to test1,test2;
授予test1用户创建表及拥有资源的权限:
grant create table,resource to test1;
test1用户连接数据库,建表,插入数据:
connect test1/123;
create table a(a number(10));
create table b(b number(10));
create table c(c number(10));
insert into a values(1);
insert into b values(2);
insert into c values(3);
commit;
从视图all_tables中查询以test开头共5个字符的拥有者的表:
--upper、lower大小写转换
select owner, table_name from all_tables
where lower(owner) like 'test_';
二、把test1用户的所有表上的查询权限授给test2用户的方法:
1、sys登录
2、执行以下语句:
--test1为拥有表的用户,test2为被授权用户,|| 为连接符
select 'grant select on '|| lower(table_name) ||' to test2;'
from all_tables
where owner = upper('test1');
3、复制以上查询结果(如下),粘贴执行,最后按一下回车执行最后一句。
grant select on a to test2;
grant select on b to test2;
grant select on c to test2;
三、测试授权成功:
connect test2/123
select * from test1.a;
select * from test1.b;
select * from test1.c;
思路:用所有表名构造grant语句,复制粘贴执行,省事。练习过程如下:
一、准备
sys用户连接数据库:
connect sys/oracle as sysdba;
建立test1、test2用户:
create user test1 identified by 123;
create user test2 identified by 123;
授予dba角色给test1:
grant dba to test1;
dba角色权限太大,收回dba角色:
revoke dba from test1;
授予test1、test2用户创建会话的权限:
grant create session to test1,test2;
授予test1用户创建表及拥有资源的权限:
grant create table,resource to test1;
test1用户连接数据库,建表,插入数据:
connect test1/123;
create table a(a number(10));
create table b(b number(10));
create table c(c number(10));
insert into a values(1);
insert into b values(2);
insert into c values(3);
commit;
从视图all_tables中查询以test开头共5个字符的拥有者的表:
--upper、lower大小写转换
select owner, table_name from all_tables
where lower(owner) like 'test_';
二、把test1用户的所有表上的查询权限授给test2用户的方法:
1、sys登录
2、执行以下语句:
--test1为拥有表的用户,test2为被授权用户,|| 为连接符
select 'grant select on '|| lower(table_name) ||' to test2;'
from all_tables
where owner = upper('test1');
3、复制以上查询结果(如下),粘贴执行,最后按一下回车执行最后一句。
grant select on a to test2;
grant select on b to test2;
grant select on c to test2;
三、测试授权成功:
connect test2/123
select * from test1.a;
select * from test1.b;
select * from test1.c;
相关文章推荐
- oracle学习记录之授权(1)
- [学习记录] oracle 给用户授权相关sql
- Oracle常见授权与回收权限(grant和revoke)学习记录
- oracle学习用户和表空间的创建,授权。
- Oracle 学习记录
- ORACLE常用函数学习记录
- Oracle学习记录1(单行函数,多行函数)
- Oracle学习记录2(多表查询)
- Oracle学习中...,笔记记录中.....1
- 数据库学习:oracle的递归写法,分析函数写法,以及teradata的取一定数量记录的写法
- Oracle SQL脚本学习记录四
- oracle学习记录之分页
- ORACLE常用函数学习记录
- [学习记录] oracle:安装过程
- Oracle学习记录
- ORACLE PL/SQL 记录(Record)学习笔记(一)
- 学习oracle 入门第一课后的笔记记录
- oracle 学习笔记(2)创建表空间及用户授权
- Oracle学习记录1(单行函数,多行函数)
- Oracle学习记录2(多表查询)