2015-09-24 27 views
1

無論如何要爲所有數據庫鏈接提取ddl嗎? 我想進入sql並通過sql重新創建它們。如何爲oracle數據庫鏈接提取ddl?

我可以在下面使用,它適用於PUBLIC用戶,但對於非公共用戶,它不會給我db連接所有者。

Set long 1000 
SELECT DBMS_METADATA.GET_DDL('DB_LINK',db.db_link,db.owner) from dba_db_links db; 

Sample link owner and name 
Owner db_link 
public link1 
public link2 
user1 link3 

如果我跑上面選擇它會給我下面,#3沒有用戶名在裏面。

Output from above SELECT 
1. create public database link "link1" using "db_alias" 
2. create public database link "link2" using "db_alias" 
3. create database link "link3" using "db_alias" 

我使用SYS重新創建鏈接,並且不想創建#3作爲SYS用戶。

回答

1

似乎即使SYS用戶不能輕鬆地爲另一個用戶創建dblink(公共dblink除外)。
即使你運行create database link your_user.link3 using "db_alias"它的主人將是SYS。 可能的黑客連接爲另一用戶
(如果您擁有憑據,您可以將conn添加到SQL * Plus腳本中)
或者爲需要使用參數運行create database link命令的dblink創建過程,並從sys中調用它。

0

這應該與做一個鏈接可以幫助「連接到」

SELECT MYCOMMAND 
FROM 
(
select trim(l.owner)||'__'||trim(l.db_link)||'__'||trim(l.username) ||'__'||trim(l.host) , '10' 
, ' connect '||trim(l.owner)||'/[email protected]'||TRIM(INSTANCE_NAME) 
AS MYCOMMAND     
from dba_db_links l , V$INSTANCE i , dba_users u 
where l.username = u.username 
and l.username is not null 
and l.username <> ' ' 
UNION ALL 
select trim(l.owner)||'__'||trim(l.db_link)||'__'||trim(l.username)||'__'||trim(l.host) , '20' 
, ' DROP DATABASE LINK '||trim(l.db_link)||' ; ' AS MYCOMMAND 
from dba_db_links l , V$INSTANCE i , dba_users u 
where l.username = u.username 
and l.username is not null 
and l.username <> ' ' 
UNION ALL 
select trim(l.owner)||'__'||trim(l.db_link)||'__'||trim(l.username)||'__'||trim(l.host) , '30' 
, ' CREATE DATABASE LINK '||trim(l.db_link) 
||' CONNECT TO "'||trim(l.username)||'"' 
||' IDENTIFIED BY "NNNNNNNN" ' 
||' USING '||trim(l.host) ||' ; 'AS MYCOMMAND 
from dba_db_links l , V$INSTANCE i , dba_users u 
where l.username = u.username 
and l.username is not null 
and l.username <> ' ' 
ORDER BY 1,2,3 
)