使用 SQL Server 的输出参数调用 Oracle 存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13741175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:28:03  来源:igfitidea点击:

Calling Oracle stored procedure with output parameter from SQL Server

sqlsql-serveroraclestored-procedureslinked-server

提问by Evgeny Levin

I have an Oracle linked server in SQL Server 2008 R2. I need to execute Oracle stored procedures (with output parameter in first, and input parameter in second procedure):

我在 SQL Server 2008 R2 中有一个 Oracle 链接服务器。我需要执行 Oracle 存储过程(第一个是输出参数,第二个过程是输入参数):

CREATE OR REPLACE PROCEDURE my1.spGetDate(CurrentDate OUT VARCHAR2)
IS
BEGIN
-- set output parameter, no select statements
END;

CREATE OR REPLACE PROCEDURE my1.spDeleteOldRecords(CurrentDate IN VARCHAR2)
IS
BEGIN
-- conditional delete from oracle table, no select statements
END;

I didn't found any complete documentation on this question, only simple examples with parameterless select/nonselect procedures, and want to know, how to call these procedures, procedures with select inside, multiparameter procedures with basic parameter types.

我没有找到关于这个问题的任何完整文档,只有带有无参数选择/非选择过程的简单示例,并且想知道如何调用这些过程、内部带有选择的过程、具有基本参数类型的多参数过程。

采纳答案by Codo

It should work like this:

它应该像这样工作:

DECLARE @dateval DATETIME

EXECUTE ('begin my1.spGetDate(?); end;', @dateval OUTPUT) AT ORA_DBLINK_NAME;

EXECUTE ('begin my1.spDeleteOldRecords(?); end;', @dateval) AT ORA_DBLINK_NAME;

If you have several parameters, it could look like this:

如果您有多个参数,则它可能如下所示:

EXECUTE ('begin my1.spProc(?,?,?,?); end;', @param_in_1, @param_in_2, @param_out_3 OUTPUT, @param_out_4 OUTPUT) AT DBLINK_NAME;

回答by Nivin Govindan

Use REF CURSOR and declare that cursor as an output variable in oracle. Using Ref Cursor you can retrieve result set from Oracle Stored procedure

使用 REF CURSOR 并将该游标声明为 oracle 中的输出变量。使用 Ref Cursor,您可以从 Oracle 存储过程中检索结果集