批量创建同义词并授权

在SYS用户下执行:

CREATE OR REPLACE PROCEDURE P_CRSYN_GRANT(V_USER IN VARCHAR2, V_OBJECT_OWNER IN VARCHAR2) IS

----V_USER         需要授权的用户
----V_OBJECT_OWNER     对象所有者

  CURSOR C_SQL_STR IS SELECT ‘CREATE OR REPLACE PUBLIC SYNONYM ‘||OBJECT_NAME ||‘ FOR ‘||V_OBJECT_OWNER||‘.‘||OBJECT_NAME  CREATE_SQL
                  FROM DBA_OBJECTS
                  WHERE OBJECT_TYPE IN
                  (‘TABLE‘, ‘VIEW‘, ‘PROCEDURE‘, ‘TRIGGER‘, ‘FUNCTION‘, ‘PACKAGE‘,‘SEQUENCE‘) AND OWNER = UPPER(V_OBJECT_OWNER);
--定义索引表数据类型
   TYPE REG_TABLE_TYPE IS TABLE OF VARCHAR2(1000)
   INDEX BY BINARY_INTEGER;
--声明索引表数据类型的变量
   V_SELECT_TABLE REG_TABLE_TYPE;

--定义参考游标数据类型
   TYPE V_REF_CURSOR IS REF CURSOR ;
--声明参考游标数据类型的变量
   C_SQL V_REF_CURSOR;

   V_GRANT_STR VARCHAR2(2000);

BEGIN

    FOR V IN C_SQL_STR LOOP
      EXECUTE IMMEDIATE V.CREATE_SQL;
    END LOOP;

    V_SELECT_TABLE(1) := ‘SELECT ‘‘GRANT SELECT,INSERT,UPDATE,DELETE ON ‘‘ ||OBJECT_NAME || ‘‘ TO ‘‘||‘‘‘||V_USER ||‘‘‘ SQLSTR FROM DBA_OBJECTS WHERE OBJECT_TYPE =‘‘TABLE‘‘ AND OWNER = UPPER(‘‘‘||V_OBJECT_OWNER||‘‘‘)‘;
    V_SELECT_TABLE(2) := ‘SELECT ‘‘GRANT SELECT,INSERT,UPDATE,DELETE ON ‘‘ ||OBJECT_NAME || ‘‘ TO ‘‘||‘‘‘||V_USER ||‘‘‘ SQLSTR FROM DBA_OBJECTS WHERE OBJECT_TYPE =‘‘VIEW‘‘ AND OWNER = UPPER(‘‘‘||V_OBJECT_OWNER||‘‘‘)‘;
    V_SELECT_TABLE(3) := ‘SELECT ‘‘GRANT EXECUTE ON ‘‘ ||OBJECT_NAME || ‘‘ TO ‘‘||‘‘‘||V_USER ||‘‘‘ SQLSTR FROM DBA_OBJECTS WHERE OBJECT_TYPE =‘‘PROCEDURE‘‘ AND OWNER = UPPER(‘‘‘||V_OBJECT_OWNER||‘‘‘)‘;
    V_SELECT_TABLE(4) := ‘SELECT ‘‘GRANT EXECUTE ON ‘‘ ||OBJECT_NAME || ‘‘ TO ‘‘||‘‘‘||V_USER ||‘‘‘ SQLSTR FROM DBA_OBJECTS WHERE OBJECT_TYPE =‘‘FUNCTION‘‘ AND OWNER = UPPER(‘‘‘||V_OBJECT_OWNER||‘‘‘)‘;
    V_SELECT_TABLE(5) := ‘SELECT ‘‘GRANT SELECT ON ‘‘ ||OBJECT_NAME || ‘‘ TO ‘‘||‘‘‘||V_USER ||‘‘‘ SQLSTR FROM DBA_OBJECTS WHERE OBJECT_TYPE =‘‘SEQUENCE‘‘ AND OWNER = UPPER(‘‘‘||V_OBJECT_OWNER||‘‘‘)‘;

     FOR INT IN V_SELECT_TABLE.FIRST .. V_SELECT_TABLE.LAST LOOP
                          OPEN C_SQL FOR V_SELECT_TABLE(INT);
             LOOP
                FETCH C_SQL INTO V_GRANT_STR;
                EXIT WHEN C_SQL%NOTFOUND;
                             EXECUTE IMMEDIATE V_GRANT_STR;
             END LOOP;

             CLOSE C_SQL;
     END LOOP;
END;
时间: 2024-11-08 00:35:32

批量创建同义词并授权的相关文章

Oracle 创建同义词

1:以sysdba登陆系统,首先创建一个用户 SQL> conn /as sysdba Connected. SQL> create user yshy identified by yshy; User created. SQL> grant connect to yshy; Grant succeeded. SQL> grant resource to yshy; Grant succeeded. SQL> grant create synonym to yshy; Gra

oralce数据库创建同义词

导语:我们不想在我们的基础平台数据库里面添加业务表格,那么我们就需要重新创建一个新的数据库,用同义词关联两个数据库. V6为基础数据库,RT为业务数据库,RT中有一张表BOOK_COUNT_MONTH 那么在V6里面创建同义词,SQL如下: -- Create the synonym create or replace synonym BOOK_COUNT_MONTH for RT.BOOK_COUNT_MONTH; 数据库显示: 附摘: 同义词概念 Oracle的同义词(synonyms)从字

oracle创建同义词

首先需要给用户创建同义词权限: SQL> grant create synonym to jhchen; Grant succeeded. 创建同义词语法: create synonym 名字 for 所有者.对象名 需要给用jhchen登陆 SQL>  create synonym eos_kpi_usersalary for kpi.eos_kpi_usersalary; Synonym created 批量更改同义词需要先在所有者那里查询: SELECT ' create synonym

centos 7 expect + shell实现批量创建文件

这个问题好久了,一直没整理出来.记得还是上次面试的时候问到如何批量修改1000台机器的主机名.这里给出批量创建内容为Hello,名为1.txt的文件. 一.首先安装expect yum install -y expect 二.准备工作:(1)准备IP地址的列表.vim ip.txt 192.168.1.88 192.168.1.89 192.168.1.90 (2)准备要执行的命令.vim cmd.txt mkdir /tmp/test 三.脚本部分 #!/bin/bash passwd="12

Linux学习笔记:创建用户与授权

一般就用GRANT来创建用户和授权 语法格式 GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level TO user_specification [, user_specification] ... [REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}] [WITH {GRANT OPTION | resource_

企业实战脚本案例2:批量创建用户并设置初始密码

批量创建用户并设置初始密码 目录: 1.脚本功能介绍 2.脚本制作技术需求 2.1 useradd命令 2.2 id命令 2.3 passwd命令 2.4 随机密码 2.5 while循环+case+select 3.脚本编写案例 一.脚本功能介绍 在企业中生产或运维中,经常会遇到VPN服务器.企业网盘.企业邮箱.云桌面私有账号等等一系列的服务器.当批量新员工入职时,经常需要批量账号分配给新员工,若此类账号存储在数据库时,管理员可根据公司账号命名规范通过专有图形化系统进行录入账号,若账号存储在系

linux实战考试题:批量创建用户和密码(不能使用循环)

批量创建10个用户,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现. 方法1: [[email protected] /]# echo stu{01..10}|tr " " "\n"|sed -r 's#(.*)#useradd \1 ; pass=$((RANDOM+10000000)); echo "$pass"|passwd --stdin \1; echo -e "

MySQL创建数据库与创建用户以及授权

MySQL创建数据库与创建用户以及授权 1.create schema [数据库名称] default character set utf8 collate utf8_general_ci;--创建数据库 采用create schema和create database创建数据库的效果一样. 2.create user '[用户名称]'@'%' identified by '[用户密码]';--创建用户 密码8位以上,包括:大写字母.小写字母.数字.特殊字符 %:匹配所有主机,该地方还可以设置成'

linux批量创建用户的脚本

#!/bin/bash for user in `cat /home/opt/userlist.txt` do mkdir -p /app/ftp/issue/merDealFiles/$user/dealFiles mkdir -p /app/ftp/issue/merDealFiles/$user/dealFiles/applyArea mkdir -p /app/ftp/issue/merDealFiles/$user/dealFiles/resultArea mkdir -p /app/