实在是受够了每次部署子系统到新机器上的繁琐,又不能把整个support库导进去,非得手动把枚举,流程和模块录进去,人都疯掉了—_—!为了偷懒,写了个迁移的存储过程,没什么技术含量。
该存储过程可以将某一类别下的流程,某一类别下的枚举,某一类别下的流程角色一次性导到远程服务器上,使用DBLINK连接到远程服务器的数据库,这里使用OOB创建DBLINK有个注意的地方,就是登录具体的用户再创建DBLINK,不能以system登录。
View Code
CREATE OR REPLACE PROCEDURE REALESTATE_SUPPORT.PROC_SYSTEMDEPLOYMENT IS /*-------子系统迁移,将本地的某一子系统流程、枚举、流程角色迁移到远程服务器-----*/ --定义变量 M_COUNT NUMBER; M_PRODEFID REALESTATE_SUPPORT.T_PRODEF.PRODEF_ID%TYPE; M_SUBPRODEFID REALESTATE_SUPPORT.T_SUBPRODEF.SUBPRODEF_ID%TYPE; M_ACTDEFID REALESTATE_SUPPORT.T_ACTDEF.ACTDEF_ID%TYPE; M_COMPONENTGUID REALESTATE_SUPPORT.T_COMPONENT.COMPONENT_GUID%TYPE; M_COMPONENT_NAME REALESTATE_SUPPORT.T_COMPONENT.COMPONENT_NAME%TYPE; M_COMPONENT_ID REALESTATE_SUPPORT.T_COMPONENT.COMPONENT_ID%TYPE; M_ACTCOMPOMENT_ID REALESTATE_SUPPORT.T_ACTCOMPOMENT.ACTCOMPOMENT_ID%TYPE; M_CONDDEF_ID REALESTATE_SUPPORT.T_CONDDEF.CONDDEF_ID%TYPE; M_ROUTEDEF_ID REALESTATE_SUPPORT.T_ROUTEDEF.ROUTEDEF_ID%TYPE; M_PRODEFMATERID REALESTATE_SUPPORT.T_PRODEFMATER.PRODEFMATER_ID%TYPE; M_PRODEFTYPEID REALESTATE_SUPPORT.T_PRODEFTYPE.PRODEFTYPE_ID%TYPE; M_OLDPRODEFTYPEID REALESTATE_SUPPORT.T_PRODEFTYPE.PRODEFTYPE_ID%TYPE; M_OLDROLETYPEID REALESTATE_SUPPORT.T_ROLETYPE.ROLETYPE_ID%TYPE; M_ROLE_ID REALESTATE_SUPPORT.T_ROLE.ROLE_ID%TYPE; M_ROLETYPEID REALESTATE_SUPPORT.T_PRODEFTYPE.PRODEFTYPE_ID%TYPE; M_OLDEXPLAINTYPEID REALESTATE_SUPPORT.T_EXPLAINTYPE.EXPLAINTYPE_ID%TYPE; M_EXPLAINTYPEID REALESTATE_SUPPORT.T_EXPLAINTYPE.EXPLAINTYPE_ID%TYPE; M_FIELDEXPLAINID REALESTATE_SUPPORT.T_FIELDEXPLAIN.FIELDEXPLAIN_ID%TYPE; M_FIELDENUM_ID REALESTATE_SUPPORT.T_FIELDENUM.FIELDENUM_ID%TYPE; --定义游标 --将某一类别下的业务流程全部迁移到服务器 这里赋一个类别的ID CURSOR C_PRODEF(PARPRODEFTYPE_ID NUMBER) IS select * from REALESTATE_SUPPORT.T_PRODEF where PRODEFTYPE_ID=PARPRODEFTYPE_ID ORDER BY PRODEFTYPE_ID; M_PRODEF C_PRODEF%ROWTYPE; --子流程 CURSOR C_SUBPRODEF(PARPRODEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_SUBPRODEF WHERE PRODEF_ID=PARPRODEF_ID ORDER BY SUBPRODEF_ID; M_SUBPRODEF C_SUBPRODEF%ROWTYPE; --活动 CURSOR C_ACTDEF(PARSUBPRODEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_ACTDEF WHERE SUBPRODEF_ID=PARSUBPRODEF_ID ORDER BY ACTDEF_ID; M_ACTDEF C_ACTDEF%ROWTYPE; --流程资料 CURSOR C_PRODEFMATER(PARPRODEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_PRODEFMATER WHERE PRODEF_ID=PARPRODEF_ID ORDER BY PRODEFMATER_ID; M_PRODEFMATER C_PRODEFMATER%ROWTYPE; --活动组件 CURSOR C_ACTCOMPOMENT(PARACTDEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_ACTCOMPOMENT WHERE ACTDEF_ID=PARACTDEF_ID ORDER BY ACTCOMPOMENT_ID; M_ACTCOMPOMENT C_ACTCOMPOMENT%ROWTYPE; --条件定义 CURSOR C_CONDDEF(PARACTDEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_CONDDEF WHERE ACTDEF_ID=PARACTDEF_ID ORDER BY CONDDEF_ID; M_CONDDEF C_CONDDEF%ROWTYPE; --路由定义 CURSOR C_ROUTEDEF(PARCONDDEF_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_ROUTEDEF WHERE CONDDEF_ID=PARCONDDEF_ID ORDER BY ROUTEDEF_ID; M_ROUTEDEF C_ROUTEDEF%ROWTYPE; --流程角色 CURSOR C_ROLE(PARROLETYPE_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_ROLE WHERE ROLETYPE_ID=PARROLETYPE_ID ORDER BY ROLE_ID; M_ROLE C_ROLE%ROWTYPE; --枚举 CURSOR C_FIELDEXPLAIN(PAREXPLAINTYPE_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_FIELDEXPLAIN WHERE EXPLAINTYPE_ID=PAREXPLAINTYPE_ID ORDER BY FIELDEXPLAIN_ID; M_FIELDEXPLAIN C_FIELDEXPLAIN%ROWTYPE; --枚举值 CURSOR C_FIELDENUM(PARFIELDEXPLAIN_ID NUMBER) IS SELECT * FROM REALESTATE_SUPPORT.T_FIELDENUM WHERE FIELDEXPLAIN_ID=PARFIELDEXPLAIN_ID ORDER BY FIELDENUM_ID; M_FIELDENUM C_FIELDENUM%ROWTYPE; BEGIN --设定要迁移的流程类别,流程角色类别 M_OLDPRODEFTYPEID:=511; M_OLDROLETYPEID:=357; M_OLDEXPLAINTYPEID:=221; --访问远程服务器,插入流程类别 SELECT REALESTATE_SUPPORT.SEQ_PRODEFTYPE.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_PRODEFTYPEID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_PRODEFTYPE@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_PRODEFTYPEID,-1,PRODEFTYPE_NAME,PRODEFTYPE_STARTDATE,PRODEFTYPE_MODIFYDATE,PRODEFTYPE_INDEX,PRODEFTYPE_STATUS,PRODEFTYPE_DESC FROM REALESTATE_SUPPORT.T_PRODEFTYPE WHERE PRODEFTYPE_ID=M_OLDPRODEFTYPEID); -----^_^卖萌的分隔线^_^ 遍历流程,访问远程服务器,它在或者不在,都让它在那里--------------------------- OPEN C_PRODEF(M_OLDPRODEFTYPEID); FETCH C_PRODEF INTO M_PRODEF; WHILE C_PRODEF%FOUND LOOP --判断是否已存在,不存在则插入 SELECT COUNT(1) INTO M_COUNT FROM REALESTATE_SUPPORT.T_PRODEF@SYSTEMDEPLOYMENT.ORACLE.COM WHERE PRODEF_NAME=M_PRODEF.PRODEF_NAME; IF M_COUNT=0 THEN SELECT REALESTATE_SUPPORT.SEQ_PRODEF.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_PRODEFID FROM DUAL; --流程定义表 INSERT INTO REALESTATE_SUPPORT.T_PRODEF@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_PRODEFID,PRODEF_NAME,OPERATION_TYPE,NULL,PRODEF_TIME,NULL,M_PRODEFTYPEID,SECONDDEPT_NAME,PRODEF_STARTDATE,PRODEF_STATUS,PRODEF_DESC,PRODEF_INDEX,PRODEF_MODIFYDATE,TRANSACTION_TYPE,PRODEF_PIGEONHOLE FROM REALESTATE_SUPPORT.T_PRODEF WHERE PRODEF_ID=M_PRODEF.PRODEF_ID); -----^_^卖萌的分隔线^_^ 遍历子流程,访问远程服务器,它在或者不在,都让它在那里------------------------------- OPEN C_SUBPRODEF(M_PRODEF.PRODEF_ID); FETCH C_SUBPRODEF INTO M_SUBPRODEF; WHILE C_SUBPRODEF%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_SUBPRODEF.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_SUBPRODEFID FROM DUAL; --子流程表 INSERT INTO REALESTATE_SUPPORT.T_SUBPRODEF@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_SUBPRODEFID,M_PRODEFID,SUBPRODEF_NAME,SUBPRODEF_INDEX,SUBPRODEF_DESC,SUBPRODEF_SINGLE,SUBPRODEF_PERMISSION,SUBPRODEF_PROCESS FROM REALESTATE_SUPPORT.T_SUBPRODEF WHERE SUBPRODEF_ID=M_SUBPRODEF.SUBPRODEF_ID); -----^_^卖萌的分隔线^_^ 遍历活动,访问远程服务器,它在或者不在,都让它在那里--------------------------------------------------------- OPEN C_ACTDEF(M_SUBPRODEF.SUBPRODEF_ID); FETCH C_ACTDEF INTO M_ACTDEF; WHILE C_ACTDEF%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_ACTDEF.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_ACTDEFID FROM DUAL; --活动表 INSERT INTO REALESTATE_SUPPORT.T_ACTDEF@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_ACTDEFID,M_SUBPRODEFID,NULL,NULL,ACTDEF_INDEX,ACTDEF_NAME,ACTDEF_TIME,ACTDEF_STARTDATE,ACTDEF_MODIFYDATE,ACTDEF_DESC,ROLLBACK_TYPE FROM REALESTATE_SUPPORT.T_ACTDEF WHERE ACTDEF_ID=M_ACTDEF.ACTDEF_ID); -----^_^卖萌的分隔线^_^ 遍历活动组件,访问远程服务器,若它在那里,就取它的ID,若它不在那里,就让它在那里,哦也------------ OPEN C_ACTCOMPOMENT(M_ACTDEF.ACTDEF_ID); FETCH C_ACTCOMPOMENT INTO M_ACTCOMPOMENT; WHILE C_ACTCOMPOMENT%FOUND LOOP SELECT COMPONENT_GUID,COMPONENT_NAME INTO M_COMPONENTGUID,M_COMPONENT_NAME FROM REALESTATE_SUPPORT.T_COMPONENT WHERE COMPONENT_ID=M_ACTCOMPOMENT.COMPONENT_ID; --先检测服务器上是否已存在此组件 SELECT COUNT(1) INTO M_COUNT FROM REALESTATE_SUPPORT.T_COMPONENT@SYSTEMDEPLOYMENT.ORACLE.COM WHERE COMPONENT_GUID=M_COMPONENTGUID AND COMPONENT_NAME=M_COMPONENT_NAME; --不存在则插入此组件 IF M_COUNT=0 THEN SELECT REALESTATE_SUPPORT.SEQ_COMPONENT.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_COMPONENT_ID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_COMPONENT@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_COMPONENT_ID,null,COMPONENT_GUID,COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_STATUS,COMPONENT_URLHOST,COMPONENT_URLPATH,COMPONENT_STARTDATE,COMPONENT_MODIFYDATE,COMPONENT_INDEX,COMPONENT_DESC FROM REALESTATE_SUPPORT.T_COMPONENT WHERE COMPONENT_ID=M_ACTCOMPOMENT.COMPONENT_ID); ELSIF M_COUNT=1 THEN SELECT COMPONENT_ID INTO M_COMPONENT_ID FROM REALESTATE_SUPPORT.T_COMPONENT@SYSTEMDEPLOYMENT.ORACLE.COM WHERE COMPONENT_GUID=M_COMPONENTGUID AND COMPONENT_NAME=M_COMPONENT_NAME; END IF; --插入活动组件 SELECT REALESTATE_SUPPORT.SEQ_ACTCOMPOMENT.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_ACTCOMPOMENT_ID FROM DUAL; --活动组件表 INSERT INTO REALESTATE_SUPPORT.T_ACTCOMPOMENT@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_ACTCOMPOMENT_ID,M_ACTDEFID,M_COMPONENT_ID,ACTCOMPOMENT_INDEX,COMPONENT_TYPE FROM REALESTATE_SUPPORT.T_ACTCOMPOMENT WHERE ACTCOMPOMENT_ID=M_ACTCOMPOMENT.ACTCOMPOMENT_ID); FETCH C_ACTCOMPOMENT INTO M_ACTCOMPOMENT; END LOOP; CLOSE C_ACTCOMPOMENT; ----------------^_^卖萌的分隔线^_^ 遍历转出条件,插入远程服务器,它在或者不在,都让它在那里---------------------------------------------------------------- OPEN C_CONDDEF(M_ACTDEF.ACTDEF_ID); FETCH C_CONDDEF INTO M_CONDDEF; WHILE C_CONDDEF%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_CONDDEF.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_CONDDEF_ID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_CONDDEF@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_CONDDEF_ID,M_ACTDEFID,CONDDEF_NAME,CONDDEF_INDEX,CONDDEF_DESC,STORAGE_MARK,DESIGNATE_DELIVER,AUTO_DELIVER FROM REALESTATE_SUPPORT.T_CONDDEF WHERE CONDDEF_ID=M_CONDDEF.CONDDEF_ID); ----------------^_^卖萌的分隔线^_^ 遍历路由,插入远程服务器, 它在或者不在,都让它在那里,杯具的是它迷路了,找不到下一个它---------------------- OPEN C_ROUTEDEF(M_CONDDEF.CONDDEF_ID); FETCH C_ROUTEDEF INTO M_ROUTEDEF; WHILE C_ROUTEDEF%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_ROUTEDEF.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_ROUTEDEF_ID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_ROUTEDEF@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_ROUTEDEF_ID,M_CONDDEF_ID,ROUTEDEF_NAME,ROUTEDEF_INDEX,ROUTE_TYPE,NULL,ROUTEDEF_DESC FROM REALESTATE_SUPPORT.T_ROUTEDEF WHERE ROUTEDEF_ID=M_ROUTEDEF.ROUTEDEF_ID); FETCH C_ROUTEDEF INTO M_ROUTEDEF; END LOOP; CLOSE C_ROUTEDEF; FETCH C_CONDDEF INTO M_CONDDEF; END LOOP; CLOSE C_CONDDEF; ----------------^_^卖萌的分隔线^_^ --------------------------------------------------- FETCH C_ACTDEF INTO M_ACTDEF; END LOOP; CLOSE C_ACTDEF; FETCH C_SUBPRODEF INTO M_SUBPRODEF; END LOOP; CLOSE C_SUBPRODEF; ----------------^_^卖萌的分隔线^_^ 遍历流程资料,访问远程服务器,它在或者不在,都让它在那里--------------- OPEN C_PRODEFMATER(M_PRODEF.PRODEF_ID); FETCH C_PRODEFMATER INTO M_PRODEFMATER; WHILE C_PRODEFMATER%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_PRODEFMATER.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_PRODEFMATERID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_PRODEFMATER@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_PRODEFMATERID,M_PRODEFID,TRANSACTION_TYPE,MATERDEF_NAME,MATERDEF_YNUM,MATERDEF_FNUM,MATERDEF_INDEX,MATERDEF_ISMUST,MATERDEF_FROMDEPT,MATERDEF_FROMADDRESS,MATERDEF_FROMPHONE,MATERDEF_DESC FROM REALESTATE_SUPPORT.T_PRODEFMATER WHERE PRODEFMATER_ID=M_PRODEFMATER.PRODEFMATER_ID); FETCH C_PRODEFMATER INTO M_PRODEFMATER; END LOOP; CLOSE C_PRODEFMATER; END IF; FETCH C_PRODEF INTO M_PRODEF; END LOOP; CLOSE C_PRODEF; ----------------^_^卖萌的分隔线^_^ 先插入流程角色类别,再遍历流程角色,访问远程服务器,它在或者不在,都让它在那里--------------- SELECT REALESTATE_SUPPORT.SEQ_ROLETYPE.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_ROLETYPEID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_ROLETYPE@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_ROLETYPEID,-1,ROLETYPE_NAME,ROLETYPE_STATUS,ROLETYPE_STARTDATE,ROLETYPE_MODIFYDATE,ROLETYPE_INDEX,ROLETYPE_DESC FROM REALESTATE_SUPPORT.T_ROLETYPE WHERE ROLETYPE_ID=M_OLDROLETYPEID); OPEN C_ROLE(M_OLDROLETYPEID); FETCH C_ROLE INTO M_ROLE; WHILE C_ROLE%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_ROLE.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_ROLE_ID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_ROLE@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT M_ROLE_ID,M_ROLETYPEID,ROLE_GUID,ROLE_NAME,ROLE_STATUS,ROLE_STARTDATE,ROLE_ENDDATE,ROLE_DELETE,ROLE_INDEX,ROLE_MODIFYDATE,ROLE_DESC FROM REALESTATE_SUPPORT.T_ROLE WHERE ROLE_ID=M_ROLE.ROLE_ID); FETCH C_ROLE INTO M_ROLE; END LOOP; CLOSE C_ROLE; ----------------^_^卖萌的分隔线^_^ 先插入枚举类别,再遍历枚举,访问远程服务器,它在或者不在,都让它在那里--------------- SELECT REALESTATE_SUPPORT.SEQ_EXPLAINTYPE.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_EXPLAINTYPEID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_EXPLAINTYPE@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT -1,M_EXPLAINTYPEID,EXPLAINTYPE_NAME,EXPLAINTYPE_INDEX,-1,EXPLAINTYPE_CREATEDATE,EXPLAINTYPE_MODIFYDATE,EXPLAINTYPE_DESC FROM REALESTATE_SUPPORT.T_EXPLAINTYPE WHERE EXPLAINTYPE_ID=M_OLDEXPLAINTYPEID); OPEN C_FIELDEXPLAIN(M_OLDEXPLAINTYPEID); FETCH C_FIELDEXPLAIN INTO M_FIELDEXPLAIN; WHILE C_FIELDEXPLAIN%FOUND LOOP SELECT COUNT(1) INTO M_COUNT FROM REALESTATE_SUPPORT.T_FIELDEXPLAIN@SYSTEMDEPLOYMENT.ORACLE.COM WHERE FIELDEXPLAIN_NAME=M_FIELDEXPLAIN.FIELDEXPLAIN_NAME AND FIELDEXPLAIN_FIELDNAME=M_FIELDEXPLAIN.FIELDEXPLAIN_FIELDNAME; IF M_COUNT=0 THEN SELECT REALESTATE_SUPPORT.SEQ_FIELDEXPLAIN.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_FIELDEXPLAINID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_FIELDEXPLAIN@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT -1,M_FIELDEXPLAINID,M_EXPLAINTYPEID,FIELDEXPLAIN_NAME,FIELDEXPLAIN_CODE,FIELDEXPLAIN_INDEX,FIELDEXPLAIN_FIELDNAME,FIELDEXPLAIN_MODIFYDATE,FIELDEXPLAIN_DESC,FIELDEXPLAIN_CREATEDATE FROM REALESTATE_SUPPORT.T_FIELDEXPLAIN WHERE FIELDEXPLAIN_ID=M_FIELDEXPLAIN.FIELDEXPLAIN_ID); ----------------^_^卖萌的分隔线^_^-遍历枚举值,访问远程服务器,它在或者不在,都让它在那里-------------------------------------------- OPEN C_FIELDENUM(M_FIELDEXPLAIN.FIELDEXPLAIN_ID); FETCH C_FIELDENUM INTO M_FIELDENUM; WHILE C_FIELDENUM%FOUND LOOP SELECT REALESTATE_SUPPORT.SEQ_FIELDENUM.NEXTVAL@SYSTEMDEPLOYMENT.ORACLE.COM INTO M_FIELDENUM_ID FROM DUAL; INSERT INTO REALESTATE_SUPPORT.T_FIELDENUM@SYSTEMDEPLOYMENT.ORACLE.COM(SELECT -1,M_FIELDENUM_ID,M_FIELDEXPLAINID,FIELDENUM_NAME,FIELDENUM_VALUE,FIELDENUM_INDEX,FIELDENUM_MODIFYDATE,FIELDENUM_DESC,-1,FIELDENUM_CREATEDATE FROM REALESTATE_SUPPORT.T_FIELDENUM WHERE FIELDENUM_ID=M_FIELDENUM.FIELDENUM_ID); FETCH C_FIELDENUM INTO M_FIELDENUM; END LOOP; CLOSE C_FIELDENUM; END IF; FETCH C_FIELDEXPLAIN INTO M_FIELDEXPLAIN; END LOOP; CLOSE C_FIELDEXPLAIN; END; /