使用输出参数调用 Oracle 存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5951667/
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
Call Oracle stored proc with output parameter
提问by Erik Westermann
I'm working with SSIS 2008 and am having a problem calling an Oracle stored procedure that has an output parameter.
我正在使用 SSIS 2008 并且在调用具有输出参数的 Oracle 存储过程时遇到问题。
I call the stored procedure in SqlPlus like this:
我在 SqlPlus 中调用存储过程是这样的:
var vresult number;
exec my_stored_procedure(:vresult);
print vresult;
The statements work and I get the output I need. I am trying to do something similar in SSIS, yet I need to do this repeatedly, maybe in a ForEach or a script to update a temporary result set with the result of calling the stored procedure (the stored procedure generates a number, and I need to add that number to each row in a result set which just holds some state information).
这些语句有效,我得到了我需要的输出。我正在尝试在 SSIS 中做类似的事情,但我需要重复执行此操作,可能在 ForEach 或脚本中使用调用存储过程的结果更新临时结果集(存储过程生成一个数字,我需要将该数字添加到只保存一些状态信息的结果集中的每一行)。
I have tried a lot of different approaches and always end up with 'invalid statement' or similar errors.
我尝试了很多不同的方法,但总是以“无效语句”或类似错误告终。
I have also tried the following approaches:
我还尝试了以下方法:
The crux of the problem seems to be the stored procedure's output parameter.
问题的症结似乎是存储过程的输出参数。
I have tried using the the Oracle Provider for OLE DB. Any ideas?
我曾尝试使用 Oracle Provider for OLE DB。有任何想法吗?
采纳答案by Erik Westermann
I came up with a solution that works:
我想出了一个有效的解决方案:
- Use the 'declare' and 'end' construct
- Combine with 'execute immediate'
- Add the 'using' statement to the end of the exec immediate to inject variable
- 使用“声明”和“结束”结构
- 结合“立即执行”
- 将 'using' 语句添加到 exec 立即注入变量的末尾
So a script that implements this might look something like this:
因此,实现此功能的脚本可能如下所示:
declare
myVar number;
myStatement varchar2(50);
begin
myStatement:='exec myProc(:1)';
execute immediate myStatement using output myVar;
end;
Paste this script into an Execute SQL task, set the task's properties and it works!
将此脚本粘贴到执行 SQL 任务中,设置任务的属性,它就可以工作了!
I'm new to Oracle but it looks like the :1 notation is a place-holder for the variable. You can test this using sqlplus too - just save the code in a file and start sqlplus using the @ option on the command line.
我是 Oracle 的新手,但看起来 :1 表示法是变量的占位符。您也可以使用 sqlplus 对此进行测试 - 只需将代码保存在文件中,然后使用命令行上的 @ 选项启动 sqlplus。
The only problem: I can't get value of the variable for use in SSIS, but that's another problem.
唯一的问题:我无法获得在 SSIS 中使用的变量的值,但这是另一个问题。
回答by Ahsan
If you are trying to invoke The stored Procedure in Oracle PLSQL this Link is very brief. http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
如果您尝试调用 Oracle PLSQL 中的存储过程,则此链接非常简短。 http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
If you are Working in Java then. The Statement Object java.sql.CallableStatement ps; ps.registerOutParameter(parameterIndex, sqlType);
如果您在 Java 中工作,那么。Statement 对象 java.sql.CallableStatement ps; ps.registerOutParameter(parameterIndex, sqlType);
Similarly .Net or Any Other Platform must will have the same Convictions. Hope so.:)
同样,.Net 或任何其他平台必须具有相同的信念。希望如此。:)
回答by Jason Marshall
check tis post: Run an Oracle package from SQL Server Integration Services
检查帖子:从 SQL Server 集成服务运行 Oracle 包
regards
问候
回答by Mezu Obi
You are almost there. In order to retrieve the value of the output parameter from the Oracle stored procedure in SSIS, here is what worked for me
你快到了。为了从 SSIS 中的 Oracle 存储过程中检索输出参数的值,这对我有用
In the Execute SQL task, paste this in the SQL statement box
在执行 SQL 任务中,将此粘贴到 SQL 语句框中
declare
vresult number;
begin
my_stored_procedure(vresult);
?:=vresult;
end;
In the Parameter Mapping, ensure to map your SSIS variable to this output of your stored procedure by setting the direction to "Output" and parameter name as "0" (if it is the first parameter)
在参数映射中,通过将方向设置为“输出”和参数名称为“0”(如果它是第一个参数),确保将 SSIS 变量映射到存储过程的这个输出
PS: ensure the Oracle output variable datatypes match your SSIS variables
PS:确保 Oracle 输出变量数据类型与您的 SSIS 变量匹配
Thanks Mezue
谢谢梅祖