oracle学习记录之授权(2)
来源:互联网 发布:大数据人才的薪资待遇 编辑:程序博客网 时间:2024/06/06 17:48
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;
- oracle学习记录之授权(2)
- oracle学习记录之授权(1)
- [学习记录] oracle 给用户授权相关sql
- oracle学习记录之二
- oracle学习记录之三
- oracle学习记录之四
- oracle学习记录之六
- oracle学习记录之七
- oracle学习记录之八
- oracle学习记录之九
- oracle学习记录之十
- oracle学习记录之十一
- oracle学习记录之十二
- oracle学习记录之十三
- oracle学习记录之十四
- oracle学习记录之十五
- oracle学习记录之十六
- oracle学习记录之十七
- Windows下字体渲染方案
- tasklet 工作队列 内核定时器 内核线程
- UIView动画(过渡效果)的学习笔记
- Linux多线程Pthread学习小结
- 1934: [Shoi2007]Vote 善意的投票 (网络流)
- oracle学习记录之授权(2)
- redis 源代码之数据结构(5)--ziplist实现
- 分治算法总结
- 将 Win32 程序移植到 Linux
- hibernate入门-02
- 使用keychain保存用户名和密码等敏感信息 KeychainItemWrapper和SFHFKeychainUtils。
- 深入分析Windows和Linux动态库应用异同
- DataSet DataTable DataReader dataAdapter区别 (转载)
- select,poll,epoll区别