这里的需求是要给LYPROG用户赋予同义词权限,并把'GRIDPROG','SJ_PROG'两个用户的对象都赋权给输入的用户名下
oracle@grid-oracle-01:/home/oracle$ ss
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 24 16:14:09 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select distinct user from dba_users;
USER
------------------------------
SYS
SQL> select username from dba_users;
USERNAME
------------------------------
LYPROG
JKPROG
OOZIE
OOZIEADMIN
HIVE
HIVEADMIN
SJ_PROG
SDE
GRIDPROG
GRIDADMIN
GRIDKEEPER
USERNAME
------------------------------
GRIDQRY
DAZHANG
UNIONMON
DIP
XS$NULL
ORACLE_OCM
DBSNMP
OLAPSYS
SI_INFORMTN_SCHEMA
ORDPLUGINS
XDB
USERNAME
------------------------------
ANONYMOUS
CTXSYS
ORDDATA
APPQOSSYS
WMSYS
EXFSYS
ORDSYS
MDSYS
SYS
SYSTEM
OUTLN
33 rows selected.
SQL> grant create synonym to LYPROG;
Grant succeeded.
SQL> select count(*) from dba_tables where owner in ('GRIDPROG','SJ_PROG');
COUNT(*)
----------
16849
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
写出一个sql文件:
oracle@grid-oracle-01:/home/oracle$ vi grant_select.sql
内容如下:
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
SPOOL temp.sql
SELECT 'GRANT SELECT ON ' || owner||'.'||object_name || ' TO &1;'
FROM dba_objects
WHERE object_type IN ('TABLE') and owner in ('GRIDPROG','SJ_PROG');
我们登录数据库并应用编辑好的sql,会产生一个temp.sql
oracle@grid-oracle-01:/home/oracle$ ss
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 24 16:18:18 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> @grant_select.sql
Enter value for 1: LYPROG
然后我们再应用产生的temp.sql即可实现批量赋权
oracle@grid-oracle-01:/home/oracle$ ss
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 24 16:19:56 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> @temp.sql