一、数据来源
应该会 
理正系统Or研发 acle数据库,连接重点 方式

SE运营 oainfo;

[url=http://tech.qq.com/a/20121115/000072.htm?_A_C_21=40247]商家 [/urlainfo;
DATABASE=lzmisuser
username:sa
password:jsjadmin
视图:eip_user_view
--步骤
一、在10.122.88.7(测试数据库)建立透明网关。
1)在10.122.88.7\e$\OraHome_1\tg4msql\admin建一个文件名为“initLZMISUSER.ora”内容是:
HS_FDS_CONNECT_INFO="SERVER=gedi-oainfo;DATABASE=lzmisuser"
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
2)在10.122.88.7\e$\OraHome_1\network\admin\listener.ora文件增加内容:
(SID_DESC=
(GLOBAL_DBNAME = LZMISUSER)
(SID_NAME = LZMISUSER)
(PROGRAM = tg4msql)
(ORACLE_HOME= E:\OraHome_1) //注意路径 当时在我本机装完透明网关后的路径是下面的
)
(SID_DESC=
(GLOBAL_DBNAME = LZMISUSER)
(SID_NAME = LZMISUSER)
(PROGRAM = tg4msql)
(ORACLE_HOME= D:\oracle\product\10.2.0\tg_1)
)
二、在正式数据库建立到理正系统数据库的DBLINK。
-- Drop existing database link
drop database link LZMIS.US.ORACLE.COM;
-- Create database link
create database link LZMIS.US.ORACLE.COM
connect to SA identified by JSJADMIN
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.122.88.7)(PORT = 1521))
)
(CONNECT_DATA =
(SID = LZMISUSER)
)
(HS=OK)
)';
三、建视图v_lz_user
create or replace view v_lz_user as
select trim("UG_UserGrpName") UG_USERGRPNAME,trim("room") ROOM,trim("SU_UserName") SU_USERNAME,trim("SU_UserCode") SU_USERCODE from eip_user_view@lzmis.us.oracle.com
四、修改表结构(如已修改了此步骤可省)
1、在EIP_SYS_USER表增加字段 HRUSER
-- Add/modify columns
alter table EIP_SYS_USER add HRUSER VARCHAR2(2);
-- Add comments to the columns
comment on column EIP_SYS_USER.HRUSER
is '数据是否来自HR,''y''是,''n''否';
2、执行
update EIP_SYS_USER set HRUSER='y';
commit;
五、修改人力数据库人员同步的JOB的内容
/*----------------同步组织机构------------------- */
--删除所有的组织机构数据
delete eip_sys_department;
--插入从人力资源数据库获得的数据
insert into eip_sys_department
select distinct section_no||dept_no,section_no,section,dept_no,dept
from pubpeople@HR_51_PROD.REGRESS.RDBMS.DEV.US.ORACLE.COM
where dept_no is not null;
insert into eip_sys_department (id,sectionid,section,deptid,dept)
values('23234','23','天联公司','234','经营部');
insert into eip_sys_department (id,sectionid,section,deptid,dept)
values('23235','23','天联公司','235','人力资源部');
insert into eip_sys_department (id,sectionid,section,deptid,dept)
values('23236','23','天联公司','236','项目部');
insert into eip_sys_department (id,sectionid,section,deptid,dept)
values('23238','23','天联公司','238','业务部');
insert into eip_sys_department (id,sectionid,section,deptid,dept)
values('23239','23','天联公司','239','综合部');
--提交
commit;
/*----------------同步组织机构完毕-------------------*/
/*----------------同步人员信息-------------------*/
/*
同步信息分成三步
1、删除掉EIP中院号为“g”开头,并且在人力资源数据库中不存在的数据
2、更新EIP和人力资源中院号相同的人员信息
3、增加在人力资源中存在,在EIP中不存在的人员信息
*/
--删除在EIP中存在,人力资源中不存在的
delete from eip_sys_user t
where username like 'g____%'
and not exists(
select 1 from pubpeople@HR_51_PROD.REGRESS.RDBMS.DEV.US.ORACLE.COM pp
where 'g'||pp.user_id=t.username) and HRUSER='y';
--同步已存在人员的姓名和部门
update eip_sys_user t
set realname = (select name from pubpeople@HR_51_PROD.REGRESS.RDBMS.DEV.US.ORACLE.COM where 'g'||user_id=t.username),
deptid = (select section_no||dept_no from pubpeople@HR_51_PROD.REGRESS.RDBMS.DEV.US.ORACLE.COM where 'g'||user_id=t.username)
where username like 'g____%' and HRUSER='y';
--增加人力资源中比EIP中多的人员
insert into eip_sys_user
select to_char(EIP_USERID.nextval),'g'||user_id,name,section_no||dept_no,'y'
from pubpeople@HR_51_PROD.REGRESS.RDBMS.DEV.US.ORACLE.COM pp
where length(pp.user_id)=4 and not exists(select 1 from eip_sys_user where username = 'g'||pp.user_id);
--更新职位信息
begin
update XT_ADDRESS_LIST_GLOB t set t.adminpost=(select adminpost from pubpeople@hr_51_prod.regress.rdbms.dev.us.oracle.com pp, eip_sys_user u where t.account=u.id and u.username = 'g'||pp.user_id);
exception
when others then
dbms_output.put_line('更新职位信息异常');
end;
--<<<<<<<<<<<<<<<天联用户>>>>>>>>>>>>
begin
--天联人员 删除
delete from eip_sys_user t
where username like 'g____%'
and not exists(
select 1 from v_lz_user pp
where pp.UG_UserGrpName like '天联公司' and 'g'||pp.SU_UserCode=t.username) and HRUSER='n';
--天联人员 修改
update eip_sys_user t
set realname = (select distinct(SU_UserName) from v_lz_user where 'g'||SU_UserCode=t.username),
deptid = (select distinct(d.id) from v_lz_user u,eip_sys_department d where u.UG_UserGrpName like '天联公司' and 'g'||u.SU_UserCode=t.username and d.section =u.UG_UserGrpName and d.dept=u.room)
where username like 'g____%' and HRUSER='n';
--天联人员 增加比EIP中多的人员
insert into eip_sys_user
select to_char(EIP_USERID.nextval),'g'||u.SU_UserCode, u.SU_UserName, d.id,'n' from v_lz_user u,eip_sys_department d
where u.UG_UserGrpName like '天联公司' and d.section =u.UG_UserGrpName and d.dept=u.room and not exists(select 1 from eip_sys_user where username = 'g'||u.SU_UserCode);
exception
when others then
dbms_output.put_line('天联公司人员同步异常');
end;
--<<<<<<<<<<<<<<<天联用户>>>>>>>>>>>>
--删除没有部门的人员
delete eip_sys_user t where t.deptid is null;
insert into eip_sys_user values( '-1','-1','系统提醒','','sg');
--提交
commit;
/*----------------同步人员信息完毕-------------------*/ |