从sqlplus调用存储过程 [英] Call stored procedure from sqlplus
本文介绍了从sqlplus调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从sqlplus调用存储过程?
How to call a stored procedure from sqlplus?
我有一个程序:
Create or replace procedure testproc(parameter1 in varachar2,parameter2 out varchar2)
begin
Do something
end;
我尝试了exec testproc(12,89)
::返回错误
I tried exec testproc(12,89)
::Returns error
推荐答案
过程的第二个参数是OUT
参数-它的值将分配给过程完成时传递的变量.因此,您不能为此参数使用文字值.
The second parameter of your procedure is an OUT
parameter -- its value will be assigned to the variable passed when the procedure completes. So you can't use a literal value for this parameter.
您可以在SQLPlus提示符下声明绑定变量,并使用该变量:
You can declare a bind variable at the SQLPlus prompt and use that:
-- Declare bind variable
VARIABLE x NUMBER
-- If necessary, initialize the value of x; in your example this should be unnecessary
-- since the value of the second parameter is never read
EXEC :x := 1
-- Call the procedure
EXEC testproc(12, :x)
-- Print the value assigned to the bind variable
PRINT x
或者,您可以使用匿名PL/SQL块:
Alternatively, you can use an anonymous PL/SQL block:
-- Activate client processing of dbms_output buffer
SET SERVEROUTPUT ON
-- In anonymous block, declare variable, call procedure, print resulting value
DECLARE
x NUMBER;
BEGIN
testproc(12, x);
dbms_output.put_line( x );
END;
/
这篇关于从sqlplus调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文