如何从 SQL Plus 执行存储过程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2115423/
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 05:10:03  来源:igfitidea点击:

How to Execute stored procedure from SQL Plus?

sqloraclestored-procedures

提问by cody

I have a stored procedure in oracle and want to test it from SQLPlus.

我在 oracle 中有一个存储过程,想从 SQLPlus 测试它。

If I use

如果我使用

execute  my_stored_proc (-1,2,0.01) 

I get this error

我收到这个错误

PLS-00306: wrong number or types of arguments in call to my_stored_proc

The beginning for the proc is this

过程的开始是这样的

create or replace PROCEDURE my_stored_proc
( a IN NUMBER, 
  b IN NUMBER, 
  c IN NUMBER, 
  z out NUMBER
) AS ....

Do I need to provide the a var for the out parameter, is so how? I tried:

我是否需要为 out 参数提供一个 var,是这样吗?我试过:

var z  NUMBER;

But get this error when I try to run the proc

但是当我尝试运行 proc 时出现此错误

execute  my_stored_proc (-1,2,0.01,z) 
PLS-00201: identifier 'Z' must be declared

Also when I was in SQL-Developer it gave me the usage and it show the inputs in reverse order, that is:

此外,当我在 SQL-Developer 中时,它给了我用法,并以相反的顺序显示输入,即:

execute my_stored_proc(z number,c number,b number,a number);

Do you provide them in reverse order or is that just something with SQL-Developer

你是按相反的顺序提供它们还是只是 SQL-Developer 的东西

I did not write the procedure and I don't normally deal with them so I could be missing something obvious.

我没有写程序,我通常不处理它们,所以我可能会遗漏一些明显的东西。

Thanks

谢谢

回答by Thilo

You have two options, a PL/SQL block or SQL*Plus bind variables:

您有两个选项,PL/SQL 块或 SQL*Plus 绑定变量:

var z number

execute  my_stored_proc (-1,2,0.01,:z)

print z

回答by R van Rijn

You forgot to put z as an bind variable.

你忘了把 z 作为绑定变量。

The following EXECUTE command runs a PL/SQL statement that references a stored procedure:

以下 EXECUTE 命令运行引用存储过程的 PL/SQL 语句:

SQL> EXECUTE -
> :Z := EMP_SALE.HIRE('Hyman','MANAGER','JONES',2990,'SALES')

Note that the value returned by the stored procedure is being return into :Z

请注意,存储过程返回的值正在返回到 :Z