oracle 将一个用户下的所有表新建到另外一个用户
转自https://www.cnblogs.com/abcwt112/p/5507917.html 将一个用户下的所有表的查看权限赋予另外一个用户
1.创建存储过程
create or replace procedure test(v_from in varchar2, v_to in varchar2) is
v_sql varchar2(1000);
cursor v_cur is
select t.* from dba_tables t where t.OWNER = v_from;
begin
for v_row in v_cur loop
--本条是将A用户的表赋给B用户查看 v_sql := 'grant select on ' || v_from || '.' || v_row.table_name || ' to ' || v_to;
v_sql := 'create table '|| v_to || '.' || v_row.table_name || ' AS select * from ' || v_from ||'.'|| v_row.table_name ;
-- dbms_output.put_line( v_sql);
execute immediate v_sql;
end loop;
end test;
2.执行
begin
-- Test statements here
test(v_from=> :v_from,
v_to => :v_to);
end;