标签: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 2012 server link 链接服务器 存储过程
原文地址:http://blog.csdn.net/waterxcfg304/article/details/43270837