首页 > 代码库 > 把包从一个数据库同步到另一个数据库
把包从一个数据库同步到另一个数据库
源库
表
create table CUX_PKG_COPY ( copy_id NUMBER, pkg_name VARCHAR2(30 ), copy_date DATE, type VARCHAR2(30 ), pkg_txt CLOB ); create sequence CUX_PKG_COPY_S start with 1; |
方法
create or replace procedure copy_pkg(p_pkg_name varchar2 ) /************************************************* -- Author : zhengxu7493 -- Created : 2016-10-04 12:15:37 -- Project : 蓝色光标财务一体化项目 -- Purpose : 同步一个包 -- 情 景 : -- Parameters: parameter1 => 输入, parameter2 => 输入, parameter3 => 输入, **************************************************/ is v_txt clob; v_pkg_name varchar2( 30) := p_pkg_name; v_count number; -- set serveroutput on; v_id number; begin delete from cux_pkg_copy pc where pc.pkg_name=p_pkg_name; v_id:=cux_pkg_copy_s.nextval; v_count := 1; for cur in (select us.TEXT from us where us.TYPE = ‘PACKAGE‘ and us.name = upper(v_pkg_name) order by us.line asc) loop if v_count = 1 then v_txt := v_txt || ‘ create or replace ‘ || cur.text; else v_txt := v_txt || cur.text; end if ; v_count := v_count + 1; end loop; --v_txt:=v_txt||‘/‘||chr(13); insert into cux_pkg_copy (copy_id, pkg_name, copy_date, type, pkg_txt) values (cux_pkg_copy_s.nextval, p_pkg_name, sysdate, ‘PACKAGE‘ , v_txt); v_txt := ‘‘; v_count := 1; for cur in (select us.TEXT from us where us.TYPE = ‘PACKAGE BODY‘ and us.name = upper(v_pkg_name) order by us.line asc) loop if v_count = 1 then v_txt := v_txt || ‘ create or replace ‘ || cur.text; else v_txt := v_txt || cur.text; end if ; v_count := v_count + 1; end loop; --v_txt:=v_txt||‘/‘; insert into cux_pkg_copy (copy_id, pkg_name, copy_date, type, pkg_txt) values (cux_pkg_copy_s.nextval, p_pkg_name, sysdate, ‘PACKAGE BODY‘ , v_txt); --p_copy_id:=v_id; end; |
目标库
create database link hec_test2uat2 connect to hecuat identified by hecuat using ‘(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST= 192.168.203.25)(PORT=1521)) (CONNECT_DATA= http://www.mamicode.com/(SERVICE_NAME=HECPROD) (INSTANCE_NAME=HECPROD)) )‘; create materialized view CUX_PKG_COPY_MV refresh complete on demand as select * from cux_pkg_copy@hec_test2uat2; |
目标库
create or replace procedure sync_pkg(p_pkg varchar2 ) is v1 number; v_clob clob; begin copy_pkg@hec_test2uat2(p_pkg); dbms_mview.refresh(list => ‘CUX_PKG_COPY_MV‘); for cur in (select * from cux_pkg_copy_mv pc where pc.pkg_name = p_pkg) loop select mv.pkg_txt into v_clob from cux_pkg_copy_mv mv where mv.copy_id=cur.copy_id; execute immediate v_clob; end loop; end; |
最近修改的包
select uo.OBJECT_NAME, uo.OBJECT_TYPE from user_objects uo where uo.OBJECT_TYPE in (‘PACKAGE‘ , ‘PACKAGE BODY‘,‘TABLE‘,‘VIEW‘) and uo.LAST_DDL_TIME > sysdate - 7 order by uo.LAST_DDL_TIME desc ; 如何使用这个方法呢? 在目标库 begin sync_pkg(包名); end; |
把包从一个数据库同步到另一个数据库
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。