executed an oracle stored procedure from sql server using the open query function

a 夏天 提交于 2019-12-13 15:26:45

问题


Can you confirm if you have successfully executed an oracle stored procedure from sql server using the open query function. If yes, How? because I am having problems executing stored procedures with arguments using the OPENQUERY Function.


回答1:


Finally tracked down a few solutions – the key to the problem (for us) is that by default RPCs are disabled for linked servers. The parameters for Rpc, Rpc Out, and Use Remote Collation need to be set to true. More info:

http://blog.sqlauthority.com/2007/10/18/sql-server-2005-fix-error-msg-7411-level-16-state-1-server-is-not-configured-for-rpc/

The solution you use will depend upon the procedure output requirements. The first example returns an output value. The second example no output values are returned (data is collected in a subsequent query).

Example 1

The procedure T2T_collect_all has two input parameters (start and end dates) and one output parameter (row count).

DECLARE @l_i_parameter1 varchar(10)

DECLARE @l_i_parameter2 varchar(10)

DECLARE @l_i_parameter3 varchar(10)

DECLARE @l_i_parameter4 varchar(10)

DECLARE @l_o_parameter1 integer

SET @l_i_parameter1 = '2009/10/01'

SET @l_i_parameter2 = 'yyyy/mm/dd'

SET @l_i_parameter3 = '2009/12/31'

SET @l_i_parameter4 = 'yyyy/mm/dd'

SET @l_o_parameter1 = 0

EXECUTE ( 'begin T2T_collect_all(to_date(?, ?), to_date(?, ?), ? ); end;',

      @l_i_parameter1, 

      @l_i_parameter2,

      @l_i_parameter3, 

      @l_i_parameter4,

      @l_o_parameter1 OUTPUT

) AT ORA_DB;

More Info: http://blogs.msdn.com/joaquinv/archive/2008/10/23/execute-oracle-stored-procedure-in-sql-server.aspx

Example 2a

The procedure T2T_collect_allx has only two input parameters (start and end dates).

EXECUTE ('begin T2T_collect_allx (SYSDATE - 40, SYSDATE); end;') ORA_DB;

Example 2b

SELECT * FROM OPENQUERY(ORA_DB, 'begin T2T_collect_allx (SYSDATE - 40, SYSDATE ); end;')




回答2:


Im no db guy, but what about adding an output parameter on the Oracle proc. Then populate it in the proc and return it to SQL server. Here is an example click here

hth, ~ck



来源:https://stackoverflow.com/questions/1652168/executed-an-oracle-stored-procedure-from-sql-server-using-the-open-query-functio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!