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