Mattan
Mattan

Reputation: 289

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

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

Upvotes: 7

Views: 42231

Answers (2)

Terri Gregory
Terri Gregory

Reputation: 31

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;

Upvotes: 3

Tony Andrews
Tony Andrews

Reputation: 132580

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;

Upvotes: 19

Related Questions