SP_COPY_DATAS暂不支持LONG类型数据的拷贝。
SP_COPY_DATAS
create or replace procedure SP_COPY_DATAS(
to_user varchar2
,is_recreate_table varchar2 default 'N'
,is_truncate_table varchar2 default 'N'
,from_dblink varchar2
,from_user varchar2 default null
,table_filter varchar2 default null
)
authid current_user
is
--通过DBLINK拷贝数据到本地
/*
create global temporary table GTMP_TABLES (
TABLE_NAME VARCHAR2(50)
) on commit preserve rows;
create global temporary table GTMP_TEXT (
text VARCHAR2(4000),
type varchar2(20)
) on commit preserve rows;
*/
v_owner1 varchar2(33) := (case when from_user is null then null else from_user || '.' end);
v_module varchar2(100) := 'SP_COPY_DATAS';
v_sql varchar2(4000);
v_date date := sysdate;
function get_copy_sql(tb_name varchar2) return varchar2 is
begin
return
('insert /*+append*/ into '||to_user||'.'||tb_name||' nologging
select * from '||v_owner1 ||tb_name||'@'||from_dblink);
end;
function get_create_sql(tb_name varchar2) return varchar2 is
begin
return
('create table '||to_user||'.'||tb_name||' nologging parallel 8 as
select * from '||v_owner1 ||tb_name||'@'||from_dblink||'
where 1 = 0');
end;
begin
--1.确定目标表
delete from gtmp_tables;
if from_user is null then
execute immediate
'insert into gtmp_tables (table_name)
select table_name from user_tables@'||from_dblink || '
where 1 = 1 ' || (case when table_filter is null then null else ' and '||table_filter end);
else
execute immediate
'insert into gtmp_tables (table_name)
select table_name from all_tables@'||from_dblink||'
where owner = '''||upper(from_user)||''''
||(case when table_filter is null then null else ' and '||table_filter end);
end if;
--2.拷贝数据
sysout(v_module,'BEGIN SP_COPY_DATAS(to_user='||to_user
||',from_dblink='||from_dblink
||',table_filter='||table_filter||')');
--2.1禁用约束
delete from GTMP_TEXT;
insert into GTMP_TEXT(TEXT,TYPE)
select 'alter table '||owner||'.'||table_name||' disable constraint '||CONSTRAINT_NAME as text
,CONSTRAINT_TYPE
from all_constraints t
where t.owner = upper(to_user)
and t.CONSTRAINT_NAME not like 'BIN$%';
sysout(v_module,'disable all constraints');
for x in (select text from GTMP_TEXT order by type desc) loop
begin
execute immediate x.text;
exception
when others then
sysout(v_module, '..' || x.text || ' error: '||sqlerrm);
end;
end loop;
sysout(v_module,'all constraints disabled');
--2.2 拷贝数据
sysout(v_module,'copy tables begin');
for x in (select table_name from gtmp_tables order by table_name) loop
begin
if is_recreate_table = 'Y' then
begin
execute immediate 'drop table '||to_user||'.'||x.table_name;
exception
when others then null;
end;
begin
execute immediate get_create_sql(x.table_name);
exception
when others then null;
end;
end if;
if is_truncate_table = 'Y' then
execute immediate 'truncate table '||to_user||'.'||x.table_name;
end if;
execute immediate get_copy_sql(x.table_name);
commit;
sysout(v_module,'..copy ' || x.table_name || ' OK');
exception
when others then
sysout(v_module,'..copy ' || x.table_name || ' error: ' || sqlerrm);
end;
end loop;
sysout(v_module,'copy tables end');
--2.3 启用约束
sysout(v_module,'enable all constraints');
for x in (select text from GTMP_TEXT order by type) loop
begin
v_sql := replace(x.text,' disable constraint ',' enable constraint ');
execute immediate v_sql;
exception
when others then
sysout(v_module, '..' || v_sql || ' error: '||sqlerrm);
end;
end loop;
sysout(v_module,'all constraints enabled');
sysout(v_module,'END SP_COPY_DATAS. Elapsed time: '||round((sysdate-v_date)*24*3600)||' seconds');
end SP_COPY_DATAS;
sysout
create or replace procedure sysout(
module_id varchar2
,text varchar2
) is
begin
dbms_output.put_line(
to_char(systimestamp,'yyyy-mm-dd hh24:mi:ss.ff3')
|| ' ['||module_id||'] ' || substr(text, 1, 1000)
);
end sysout;
分享到:
相关推荐
Linux下ORACLE 使用dblink连接mysql_lijilinjy的专栏-CSDN博客.mhtml
Oracle之dblink的配置 Oracle之dblink的配置 Oracle之dblink的配置 Oracle之dblink的配置
以迁移scott用户下所有的表为例演示Oracle使用dblink导用户下的所有表数据
执行存储过程,通过指定目标数据库登录信息,动态生成dblink,打开游标,按批次插入本地指定表中,每批次1万条数据。同步记录和日志信息写在自动生成的sync_log表中。同步完成后自动删除动态生成的存储过程、dblink...
oracle通过DBlink连接mysql搭建过程
ORA-12154_TNS无法解析指定的连接标识符
本周由于公司一个系统的oracle数据库需要采集另一个系统mysql数据库的数据,于是对oracle通过dblink连接mysql进行了研究,测试环境是单实例oracle 10g 64位,折腾了半天搞定了,但是生产环境是10g rac,原本以为会很...
通过dblink连接oracle和mysql,将数据从oracle传输到mysql,详细记录了搭建过程和创建报错
依赖包:mysql-connector-odbc-5.3.6-1.el6.x86_64.rpm和unixODBC,前置条件:Oracle和MySQL字符集需要一致,否则Oracle查询出来的数据是乱码。
oracle,oracle_dblink详解
oracle 创建dblink的详细步骤,以及使用oracle快照快速的刷新,保持本地与远程数据库的同步
oracle通过dblink连接mysql,主要参考了网上的文章,由于本人oracle服务端是32位,MySQL是64,附件中包含32位驱动 mysql-connector-odbc-5.2.4-ansi-win32.msi
本文详细描述了在oracle10g或11g中使用dblink访问sql server,使用oracle的透明网关来访问异构的数据库,方便一些习惯使用oracle的开发人员操作sql server数据库
Oracle10g通过DBLink访问MySQL数据 安装环境:Windows_Server2003, Oracle10gR2, MySQL4(服务器版在另外电脑上),MySql-Connector3.51(客户端ODBC驱动) 。
Oracle10g通过DBLink访问MySQL数据(Windows)
oracle数据库之间同步数据 dbLink +job方式
oracle通过dblink链接 mysql和mssql例子 databaselink是定义一个数据库到另一个数据库的路径的对象,databaselink允许 你查询远程表及执行远程程序。在任何分布式环境里,database都是必要的。另外要注意 的是...
oracle通过ODBC建立dblink访问SqlServer数据库配置
oracle通过odbc方式,连接到sqlserver数据库。比透明网关方式更加简单
Oracle-不同数据库DBLINK导数据使用说明