繁体   English   中英

从sqlplus调用存储过程

[英]Call stored procedure from sqlplus

如何从sqlplus调用存储过程?

我有一个程序:

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

Do something

end;

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

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

您可以在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

或者,您可以使用匿名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;
/
   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);

试试这个,如果你有问题,请再次发给我:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM