如何调用 pl/sql 存储过程(函数,返回数值)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4062695/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:04:35  来源:igfitidea点击:

How can i call pl/sql stored procedure (function, returning number value)?

sqloracleplsqlsqlplusoracle-sqldeveloper

提问by Mattan

I'm using Oracle SQL developer, or Oracle SQL* Plus

我正在使用 Oracle SQL 开发人员或 Oracle SQL* Plus

回答by Tony Andrews

In SQL Plus you can do this:

在 SQL Plus 中,您可以这样做:

var x number
exec :x := myfunction();

Or you may be able to use SQL:

或者您可以使用 SQL:

select myfunction() from dual;

回答by Terri Gregory

The example above shows how to call a function from SQL*Plus. If you're calling a function from a PL/SQL procedure, see the example below.

上面的示例显示了如何从 SQL*Plus 调用函数。如果您从 PL/SQL 过程调用函数,请参见下面的示例。

DECLARE
    x NUMBER;
BEGIN
    x := myfunction();
END;


A more complex example that will return a value of 100 (10*10):

将返回值 100 (10*10) 的更复杂示例:

DECLARE

  x NUMBER;

  FUNCTION mysquare(in_y IN NUMBER) RETURN NUMBER IS
  BEGIN
    RETURN in_y * in_y;
  END mysquare;

BEGIN

  dbms_output.enable;
  x := mysquare(10);
  dbms_output.put_line(x);

END;