日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
通過SQLAgent實現(xiàn)Oracle與SQLServer表數(shù)據(jù)同步

將SQLServer2008中的某些表同步到Oracle數(shù)據(jù)庫中,不同數(shù)據(jù)庫類型之間的數(shù)據(jù)同步我們可以使用鏈接服務(wù)器和SQLAgent來實現(xiàn)

創(chuàng)新互聯(lián)于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計、網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元陽朔做網(wǎng)站,已為上家服務(wù),為陽朔各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108

實例1:

SQLServer2008有一個表employ_epl是需要同步到一個EHR系統(tǒng)中(Oracle11g),實現(xiàn)數(shù)據(jù)庫的同步步驟如下:

1.在Oracle中建立對應(yīng)的employ_epl表,需要同步哪些字段我們就建那些字段到Oracle表中。 注意:Oracle的數(shù)據(jù)類型和SQLServer的數(shù)據(jù)類型是不一樣的,需要進(jìn)行轉(zhuǎn)換

–查看SQLServer和其他數(shù)據(jù)庫系統(tǒng)的數(shù)據(jù)類型對應(yīng)關(guān)系 –SQL轉(zhuǎn)Oracle的類型對應(yīng)

SELECT *FROM msdb.dbo.MSdatatype_mappings

–詳細(xì)得顯示了各個數(shù)據(jù)庫系統(tǒng)的類型對應(yīng)

SELECT *FROM msdb.dbo.sysdatatypemappings

2.建立鏈接服務(wù)器 將Oracle系統(tǒng)作為SQL Server的鏈接服務(wù)器加入到SQL Server中。

http://www.linuxidc.com/Linux/2016-04/130574.htm

3.使用SQL語句通過鏈接服務(wù)器將SQLServer數(shù)據(jù)寫入Oracle中

DELETE FROM TESTORACLE..SCOTT.EMPLOY_EPL
insert into TESTORACLE..SCOTT.EMPLOY_EPL
select * from employ_epl

–查看Oracle數(shù)據(jù)庫中是否已經(jīng)有數(shù)據(jù)了。

select * from TESTORACLE..SCOTT.EMPLOY_EPL

4.建立SQLAgent,將以上同步SQL語句作為執(zhí)行語句,每天定時同步。

實例2:依靠”作業(yè)”定時調(diào)度存儲過程來操作數(shù)據(jù),增,刪,改,全在里面,結(jié)合觸發(fā)器,游標(biāo)來實現(xiàn),關(guān)于作業(yè)調(diào)度,使用了5秒運行一次來實行”秒級作業(yè)”,這樣基本就算比較快的”同步”

–1.準(zhǔn)備一個新表 –SqlServer表EmployLastRec_Sql用于記錄employ_epl表的增刪改記錄 CREATE TABLE [dbo].[EmployLastRec_Sql](https://www.zmtbox.com/tools/[id] [int] IDENTITY(1,1) NOT NULL, [modiid] [int] NULL, [IsExec] [int] NULL, [epl_employID] varchar NULL, [epl_employName] varchar NULL, [epl_Sex] [int] NULL, [epl_data] [datetime] NULL)

–2.用一個視圖”封裝”了一下鏈接服務(wù)器下的一張表

create view v_ora_employ
as
 --TESTORACLE鏈接服務(wù)器名
 select * from TESTORACLE..SCOTT.EMPLOY_EPL

–3.SQL2008表employ_epl建立觸發(fā)器,用表EmployLastRec_Sql記錄下操作的標(biāo)識 –modiid等于1為insert,2為delete,3為update,字段isexec標(biāo)識該條記錄是否已處理,0為未執(zhí)行的,1為已執(zhí)行的

create trigger trg_employ_epl_insert on employ_epl for insert
as
 insert into EmployLastRec_Sql(modiid,IsExec,epl_employID,epl_employName,epl_Sex)
 select '1','0',epl_employID,epl_employName,epl_Sex from inserted


create trigger trg_employ_epl_update on employ_epl for update
as
 insert into EmployLastRec_Sql(modiid,IsExec,epl_employID,epl_employName,epl_Sex)
 select '3','0',epl_employID,epl_employName,epl_Sex from inserted


create trigger trg_employ_epl_delete on employ_epl for delete
as
 insert into EmployLastRec_Sql(modiid,IsExec,epl_employID,epl_employName,epl_Sex)
 select '2','0',epl_employID,epl_employName,epl_Sex from deleted

–4.創(chuàng)建存儲過程進(jìn)行導(dǎo)數(shù)到ORACLE –使用游標(biāo)逐行提取EmployLastRec_Sql記錄,根據(jù)modiid判斷不同的數(shù)據(jù)操作,該條記錄處理完畢后把isexec字段更新為1.

create proc sp_EmployLastRec_Sql
as --epl_employID,epl_employName,epl_Sex
 declare @modiid int
 declare @employID varchar(30)
 declare @employName varchar(50)
 declare @sex int

–字段IsExec標(biāo)識該條記錄是否已處理,0為未執(zhí)行的,1為已執(zhí)行的

if not exists(select * from EmployLastRec_Sql where IsExec=0)
 begin  
   truncate table EmployLastRec_Sql----不存在未執(zhí)行的,則清空表
 return
 end

 declare cur_sql cursor for
   select modiid,epl_employID,epl_employName,epl_Sex
   from EmployLastRec_Sql where IsExec=0 order by [id]--IsExec 0為未執(zhí)行的,1為已執(zhí)行的

 open cur_sql
 fetch next from cur_sql into @modiid,@employID,@employName,@sex
 while @@fetch_status=0
 begin
   if (@modiid=1) --插入
   begin
     ----將數(shù)據(jù)插入到ORACLE表中
     insert into v_ora_employ(epl_employID,epl_employName,epl_Sex)values(@employID,@employName,@sex)
   end

?    if (@modiid=2) --刪除
?    begin
?      delete from v_ora_employ where epl_employID=@employID
?    end

?    if (@modiid=3) --修改
?    begin
?      update v_ora_employ set epl_employName=@employName,epl_Sex=@sex,epl_data=getdate()
?      where epl_employID=@employID
?    end

?    update EmployLastRec_Sql set IsExec=1   where current of cur_sql

?    fetch next from cur_sql into @modiid,@employID,@employName,@sex
 end

 deallocate cur_sql

–5.調(diào)用該存儲過程的作業(yè),實現(xiàn)5秒執(zhí)行一次該存儲過程,做到5秒數(shù)據(jù)同步。 –先建一個一分鐘運行一次的作業(yè),然后在”步驟”的腳本中這樣寫:

DECLARE @dt datetime
SET @dt = DATEADD(minute, -1, GETDATE())
--select @dt
WHILE @dt '00:00:05' -- 等待5秒, 根據(jù)你的需要設(shè)置即可
END

當(dāng)前標(biāo)題:通過SQLAgent實現(xiàn)Oracle與SQLServer表數(shù)據(jù)同步
鏈接URL:http://m.5511xx.com/article/dpgjhhe.html