SQL SERVER連結的伺服器執行帶參預存程序

來源:互聯網
上載者:User

標籤: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連結的伺服器執行帶參預存程序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.