I needed to access data from a live database, add some views and procedures, but I did not want to touch the schema. I wrote a script to create synonyms for all the remote schema object using a database link. There could be other uses for such shortcuts, for e.g providing more restrictive access, among others. Here is the script.
-- parameter 1: db link name
-- parameter 2: remote username
-- parameter 3: remote user password
-- parameter 4: remote hostname/sid
-- usage: mydblink user password remote_host/database_sid
-- NOTE: Tested on 10g
-- grant CREATE DATABASE LINK privilege to the user
-- DISCLAIMER: Use at your own risk
set serveroutput on
drop database link &1;
--create database link
create database link &1 connect to &2 identified by &3 using '&4';
--link all the database objects
DECLARE
l_count NUMBER;
BEGIN
FOR rec IN
(SELECT object_name FROM user_objects@&1 WHERE object_type in
('SEQUENCE', 'TABLE', 'VIEW', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION',
'SYNONYM', 'PROCEDURE', 'TYPE')
)
LOOP
dbms_output.put_line('Creating ' || rec.object_name);
SELECT COUNT(*) into l_count FROM user_synonyms where synonym_name = rec.object_name;
IF l_count > 0 THEN
EXECUTE IMMEDIATE 'DROP SYNONYM ' || rec.object_name;
END IF;
EXECUTE IMMEDIATE 'CREATE SYNONYM ' || rec.object_name
|| ' FOR ' || rec.object_name || '@&1';
END LOOP;
end;
/
Gnome Switches Nautilus Back To Browser Mode
33 minutes ago

0 comments:
Post a Comment