Oracle跨库清洗数据数据
说明:需要从a库的sysuser表 清洗数据到b库的user表中
以下脚本都是直接执行的,不需要创建函数或者存储过程
创建数据库连接
CREATE PUBLIC DATABASE LINK 连接名 CONNECT TO 数据库用户名 IDENTIFIED BY "数据库密码 保留双引号" USING '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =IP地址)(PORT =端口号 ))
)
(CONNECT_DATA =
(SERVICE_NAME =数据库实例sid)
)
)';
声明中得public是共有的,如果想创建私有的连接,去掉public即可 eg:
CREATE PUBLIC DATABASE LINK dblink CONNECT TO sysorg IDENTIFIED BY "sysorg" USING '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =127.0.0.1)(PORT =1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME =ORCL)
)
)';
校验数据库连接是否创建成功:
select * from dba_db_links;
校验数据库连接是否可访问:
SELECT SYSDATE FROM dual@连接名;
SELECT SYSDATE FROM dual@dblink
删除数据库连接:如果创建的是private的连接,则去掉public即可
drop public database link 连接名;
drop public database link dblink;
使用:
insert into user(ID, NAME)SELECT w.ID, w.NAME from sysuser@dblink w