set echo off feedback off verify off pagesize 0 linesize 120

define v_grantee=&1

define v_grant_sel_command_file = .\log\grant_sel_&v_grantee..sql
define v_grant_sel_log_file     = .\log\grant_sel_&v_grantee..log

spool &v_grant_sel_command_file.
prompt spool &v_grant_sel_log_file.
prompt set echo on feedback on
prompt show user

----将原有的权限赋予用户,no exsists ( select null于(select *)差不多)  就是where如果子查询没有返回行,则----则满足 NOT EXISTS 中的 ----WHERE 子句,目的应该是检查是否表的权限是否有丢失。

----按照每个表的权限进行遍历

select
  'grant select on ' || t.table_name || ' to &v_grantee with grant option;'
from     user_tables t
where not exists
  (select null
   from   user_tab_privs p
   where  p.owner      = user
   and    p.table_name = t.table_name
   and    p.grantee    = upper('&v_grantee'))
and user != upper('&v_grantee')
order by t.table_name
/

--

select
  'grant select on ' || v.view_name  || ' to &v_grantee with grant option;'
from     user_views v
where not exists
  (select null
   from   user_tab_privs p
   where  p.owner      = user
   and    p.table_name = v.view_name
   and    p.grantee    = upper('&v_grantee'))
and user != upper('&v_grantee')
order by v.view_name
/
select
  'grant execute on ' || o.object_name || ' to &v_grantee;'
from     user_objects o
where object_type in ('PACKAGE')
and   not exists
  (select null
   from   user_tab_privs p
   where  p.owner      = user
   and    p.table_name = o.object_name
   and    p.grantee    = upper('&v_grantee'))
and user != upper('&v_grantee')
order by o.object_name
/

prompt set echo off feedback off
prompt spool off
spool off

@&v_grant_sel_command_file.

补充测试说明:

data user: for ddl usr

user: for app dml/select (同义词)

patch user: for app supprot user (同义词)

query    : for app supprot user   (同义词)

##

step 1:

检查  data user的表是否给了权限usr user.

变量为: dbUSR

select *    from   user_tab_privs p    where  p.owner      = user    and    p.grantee    = upper('&v_grantee'))    and user != upper('&v_grantee')

step 2.1: 测试取消data user 的表的update/select权限

revoke update on testfrom dbUSR; revoke  select  on testfrom dbUSR;

step 3.1: 测试脚本01_schema_rollout.sql能否将的表的update/select权限 重新授权

测试01_schema_rollout.sql 结果:无法将2个权限 重新授权

step 2.2: 测试取消data user 的表的delete/insert权限

revoke insert on testfrom dbUSR;

revoke delete on testfrom dbUSR;

step 3.2: 测试脚本能否将的表的delete/insert/update/select权限 重新授权

测试01_schema_rollout.sql 结果:可以

step  2.3 删除一个表。然后使用备份表(.sql)文件恢复,是可行的。(.sql 文件包含授权grant命令 )

step 3.3 同义词 状态是invalide,可以忽略。

原因如下: 先建一个可用的同义词,然后将该同义词对应的表删除,dba_objects对应的状态就是INVALID了  然后当你再去select这个同义词的时候,status又会变成VALID.

gen_grant_sel.sql的更多相关文章

  1. call_grant_sel.sql

    set echo offpromptprompt =========================================================================== ...

  2. 最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目

    最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目 最近一个来自重庆的客户找到走起君,客户的业务是做移动互联网支付,是微信支付收单渠道合作伙伴,数据库里存储的是支付流水和交易流水 ...

  3. SQL Server 大数据搬迁之文件组备份还原实战

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...

  4. Sql Server系列:分区表操作

    1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...

  5. SQL Server中的高可用性(2)----文件与文件组

        在谈到SQL Server的高可用性之前,我们首先要谈一谈单实例的高可用性.在单实例的高可用性中,不可忽略的就是文件和文件组的高可用性.SQL Server允许在某些文件损坏或离线的情况下,允 ...

  6. EntityFramework Core Raw SQL

    前言 本节我们来讲讲EF Core中的原始查询,目前在项目中对于简单的查询直接通过EF就可以解决,但是涉及到多表查询时为了一步到位就采用了原始查询的方式进行.下面我们一起来看看. EntityFram ...

  7. 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)

    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...

  8. 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)

    从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...

  9. 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)

    从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...

随机推荐

  1. 学习multiprocessing

    1. multiprocessing.Pool from multiprocessing.pool import Pool def gen_row(): ...return rows def main ...

  2. WebService测试方案

    1.WebService简介 WebService是一种革命性的分布式计算技术,本质上就是网络上可用的API,可以直接在网络环境调用的方法. WebService常用的框架有axis.xfire.cx ...

  3. thinkphp整合系列之phpexcel生成生成excel文件

    在后台管理中会经常需要将数据生成excel表格的: php生成excel有两种方案: 一种是通过phpexcel生成xls格式的表格文件: 另一种则直接通过逗号换行生成csv格式的表格文件: 这里先讲 ...

  4. 认识ASP.NET MVC的5种AuthorizationFilter

    在总体介绍了筛选器及其提供机制(<深入探讨ASP.NET MVC的筛选器>)之后,我们按照执行的先后顺序对四种不同的筛选器进行单独介绍,首先来介绍最先执行的AuthorizationFil ...

  5. LeetCode OJ 189. Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  6. 关于stringWithFormat: - 两段NSString如何合成一段

    http://blog.sina.com.cn/s/blog_6b1e4a0601019pib.html str = [NSString stringWithFormat:@"%@,%@&q ...

  7. 状压dp找寻环的个数 Codeforces Beta Round #11 D

    http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...

  8. replication across two data centers

    http://andyhan.net/index.php/sys-adm/item/291-hbase-replication http://shitouer.cn/2013/04/hbase-mul ...

  9. 打开另外一个App

    /** * 打开一个app * * @param packageName * @param data * @return */ public static boolean lanuchApp(Cont ...

  10. UML示例图