--本次因工作需要,为其他部门提供部分表数据,创建一个新用户与表空间。
--system用户下
drop user sys_outside cascade;
drop tablespace sys_outside including contents and datafiles;
create tablespace sys_outside
datafile ‘/u01/app/oracle/oradata/dbxxx/sys_outside.dbf‘
size 100M autoextend on next 10M maxsize 20000M;
create user sys_outside identified by sys_outside default tablespace sys_outside ;
GRANT
CONNECT,
RESOURCE,
create synonym
TO sys_outside ;
--只在当前表空间有上述权限,如果想要在其他表空间也有权限,可执行以下命令
GRANT
CONNECT,
--RESOURCE,
--DBA,
unlimited tablespace,
create synonym,
CREATE SEQUENCE,
CREATE TABLE,
CREATE VIEW,
CREATE INDEX,
CREATE PROCEDURE,
CREATE DIRECTORY,
ALTER SESSION,
ALTER SEQUENCE,
ALTER TABLE,
ALTER VIEW,
ALTER INDEX,
ALTER PROCEDURE,
--ALTER DIRECTORY,
--DROP SESSION,
DROP SEQUENCE,
DROP TABLE,
DROP VIEW,
DROP INDEX,
DROP PROCEDURE,
--DROP DIRECTORY,
SELECT TABLE,
SELECT DICTIONARY,
INSERT TABLE,
UPDATE TABLE,
DELETE TABLE,
DEBUG ANY PROCEDURE,
DEBUG CONNECT SESSION,
execute any procedure
TO sys_outside ;
--给用户赋予查询其他表空前指定表、视图权限
grant select on SYS_TEST.ZK_VIEW to sys_outside;
grant select on SYS_TEST.ZK_COUNTRY_VIEW to sys_outside;
--登录新创建的用户,创建同义词,使查询语句更简洁
create or replace synonym ZK_VIEW for SYS_TEST.ZK_VIEW;
create or replace synonym ZK_COUNTRY_VIEW for SYS_TEST.ZK_COUNTRY_VIEW;
--当需要赋权的数据过多时,可执行以下语句,将结果复制选取自己想要的进行执行
-- 将结果集取出来,在sql种执行
select ‘grant select on ‘||owner||‘.‘||object_name||‘ to sys_outside;‘
from dba_objects
where owner in (SYS_TEST‘) and object_type=‘TABLE‘;
-- 将结果集取出来,在sql种执行select ‘create or replace synonym ‘||object_name||‘ for ‘||owner||‘.‘||object_name||‘;‘ from dba_objects where owner in (‘SYS_TEST‘) and object_type=‘TABLE‘;