SQL Server linked server execution with parameter stored procedure

Source: Internet
Author: User

SQL Server links to the Oracle database via a linked server, and I'm going to write a stored procedure on the SQL Server database that uses the linked service to fetch data from the Oracle database, which is a stored procedure with parameters. Create a stored procedure in the SQL SERVER database to fetch the data from a table in the Oracle database as follows:

1. Create a stored procedure on a SQL Server database

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, execute the stored procedure
exec test_getdata_from_oracle ' 1979-01-01 '





Note: For details on how to establish an Oracle linked server, please refer to the blog post:http://blog.csdn.net/waterxcfg304/article/details/43162403

SQL Server linked server execution with parameter stored procedure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.