gpt4 book ai didi

sql - 从 sqlplus 调用存储过程

转载 作者:行者123 更新时间:2023-12-01 07:29:36 24 4
gpt4 key购买 nike

如何从 sqlplus 调用存储过程?

我有一个程序:

Create or replace procedure testproc(parameter1 in varachar2,parameter2 out varchar2)
begin

Do something

end;

我试过 exec testproc(12,89)::返回错误

最佳答案

程序的第二个参数是 OUT参数——它的值将分配给过程完成时传递的变量。因此,您不能为此参数使用文字值。

您可以在 SQLPlus 提示符下声明一个绑定(bind)变量并使用它:

-- 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 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;
/

关于sql - 从 sqlplus 调用存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com