標籤:sql server 2012 server link 連結的伺服器 預存程序
SQL SERVER通過連結的伺服器,連結到ORACLE資料庫,下面我要在SQL SERVER資料庫上寫一個預存程序,該預存程序需要用通過連結服務去取ORACLE資料庫裡的資料,該預存程序是含參數的預存程序。在SQL SERVER 資料庫裡建立一個預存程序來取ORACLE資料庫裡的一個表裡的資料如下:
1,在SQL SERVER資料庫上建立預存程序
USE [ProdDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Test_Getdata_From_Oracle]
-- Add the parameters for the stored procedure here
@P_AS_OF_birthday datetime
AS
BEGIN
declare @E_SQL varchar(2000);
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
set @E_SQL = ‘insert into test ‘ +
‘select * from openquery(ORACLE11G, ‘‘select * from test.test where birthday = ‘‘‘‘‘
+ CONVERT(varchar, @P_AS_OF_birthday, 111) + ‘‘‘‘‘ ‘‘) ‘;
print @E_SQL;
execute(@E_SQL);
END
GO
2,執行預存程序
exec Test_Getdata_From_Oracle ‘1979-01-01‘
Note:具體的如何建立ORACLE連結的伺服器,請參考博文:http://blog.csdn.net/waterxcfg304/article/details/43162403
SQL SERVER連結的伺服器執行帶參預存程序