我想在oracle中写一行,以便可以一次将表的选择特权授予多个模式。
这是我所拥有的,但是出现语法错误:
GRANT SELECT ON OWNER.TABLE_NAME to (select distinct owner from dba_objects where owner like 'SCHEMA_%');
答案 0 :(得分:2)
您需要动态SQL来做到这一点,例如
SQL> declare
2 l_str varchar2(200);
3 begin
4 for cur_r in (select 'MIKE' username from dual union all
5 select 'IMPORTER' from dual union all
6 select 'DIP' from dual
7 )
8 loop
9 l_str := 'grant select on emp to ' || cur_r.username;
10 dbms_output.put_line(l_str);
11 execute immediate l_str;
12 end loop;
13 end;
14 /
grant select on emp to MIKE
grant select on emp to IMPORTER
grant select on emp to DIP
PL/SQL procedure successfully completed.
SQL>
我使用数据库中的多个用户在游标FOR循环中获取用户名;您可以用自己的select distinct owner from dba_objects where owner like 'SCHEMA_%'
代替它。