使用IN和OUT参数在Oracle中调用存储过程 [英] Calling a stored procedure in Oracle with IN and OUT parameters
本文介绍了使用IN和OUT参数在Oracle中调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此过程:
CREATE OR REPLACE PROCEDURE PROC1(invoicenr IN NUMBER, amnt OUT NUMBER)
AS BEGIN
SELECT AMOUNT INTO amnt FROM INVOICE WHERE INVOICE_NR = invoicenr;
END;
因此,当我像这样运行它时,它绝对不会返回任何内容:
So when I run it like this it returns absolutely nothing:
DECLARE
amount NUMBER;
BEGIN
PROC1(1000001, amount);
dbms_output.put_line(amount);
END;
顺便说一句,我使用DreamCoder for Oracle.程序本身或我的调用方式是否有问题?在INVOICE表中,有一个INVOICE_NR等于1000001的条目.
BTW I use DreamCoder for Oracle. Is there a problem with the procedure itself or with the way I call it? There is an entry in the INVOICE table with INVOICE_NR equal to 1000001.
推荐答案
如果在整个代码之前将服务器输出设置为ON模式,则它将起作用,否则put_line()将不起作用.试试吧!
If you set the server output in ON mode before the entire code, it works, otherwise put_line() will not work. Try it!
代码是
set serveroutput on;
CREATE OR REPLACE PROCEDURE PROC1(invoicenr IN NUMBER, amnt OUT NUMBER)
AS BEGIN
SELECT AMOUNT INTO amnt FROM INVOICE WHERE INVOICE_NR = invoicenr;
END;
然后按原样调用该函数:
And then call the function as it is:
DECLARE
amount NUMBER;
BEGIN
PROC1(1000001, amount);
dbms_output.put_line(amount);
END;
这篇关于使用IN和OUT参数在Oracle中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文