Thursday, November 1, 2012

Script to create Synonym for all Objects for a particular Schema

-- Please give the User Name in v_user variable

declare
cursor cur_synonym(p_user varchar2)
is
select 'CREATE SYNONYM '||p_user||'.'
           || db.object_name
           || ' FOR APPS.'
           || db.object_name sql_stmt
  from dba_objects db
where db.owner = 'APPS'
;


v_user varchar2(20) := 'USER_NAME';

begin

for i in cur_synonym(v_user) loop

     execute immediate i.sql_stmt ;

     dbms_output.put_line('Command : '||i.sql_stmt);

end loop;

exception
     when others then
          dbms_output.put_line('Error: '||sqlerrm);

end;
/

No comments:

Post a Comment