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

发布于 2024-09-30 11:15:00 字数 52 浏览 1 评论 0原文

我正在使用 Oracle SQL Developer 或 Oracle SQL* Plus

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

棒棒糖 2024-10-07 11:15:00

在 SQL Plus 中,您可以执行以下操作:

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

或者您也可以使用 SQL:

select myfunction() from dual;

In SQL Plus you can do this:

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

Or you may be able to use SQL:

select myfunction() from dual;
水中月 2024-10-07 11:15:00

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

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

一个更复杂的示例将返回值 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;

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.

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

A more complex example that will return a value of 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文