SQL 从 sqlplus 调用存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8558711/
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 stored procedure from sqlplus
提问by Rupesh
How to call a stored procedure from sqlplus?
如何从sqlplus调用存储过程?
I have a procedure:
我有一个程序:
Create or replace procedure testproc(parameter1 in varachar2,parameter2 out varchar2)
begin
Do something
end;
I tried exec testproc(12,89)
::Returns error
我试过 exec testproc(12,89)
::Returns 错误
回答by Dave Costa
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.
过程的第二个参数是一个OUT
参数——它的值将分配给过程完成时传递的变量。因此,您不能为此参数使用文字值。
You can declare a bind variable at the SQLPlus prompt and use that:
您可以在 SQLPlus 提示符下声明一个绑定变量并使用它:
-- 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
Alternatively, you can use an anonymous PL/SQL block:
或者,您可以使用匿名 PL/SQL 块:
-- 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;
/
回答by Rupesh
create or replace procedure autogenerate(t1 in int,t2 in int)
is
jum number;
begin
if t1 < 10 then
dbms_output.put_line('Value too low.');
else if t1 > 20 then
dbms_output.put_line('Value too high.');
end if;
end if;
end;
/
show errors;
set serveroutput on;
execute autogenerate(1,2);
Try this, if you have question just post it again to me :)
试试这个,如果你有问题,请再发一次给我:)