Returning values with functions : Function Return « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL>
SQL> create or replace function getArea (i_rad NUMBER)
  2  return NUMBER
  3  is
  4  begin
  5    return 3.14 * (i_rad**2);
  6  end;
  7  /

Function created.

SQL>
SQL> create or replace function f_getDiff(i_rad1 NUMBER,i_rad2 NUMBER)
  2    return NUMBER is
  3          v_area1 NUMBER;
  4          v_area2 NUMBER;
  5          v_out NUMBER;
  6  begin
  7        v_area1 := getArea (i_rad1);
  8        v_area2 := getArea (i_rad2);
  9        v_out   :=v_area1-v_area2;
 10        return v_out;
 11  end;
 12  /

Function created.

SQL>
SQL> declare
  2    v_pi NUMBER:=3.14;
  3
  4
  5  begin
  6    DBMS_OUTPUT.put_line('Diff between 3 and 4: '||f_getDiff(4,3));
  7    DBMS_OUTPUT.put_line('Diff between 4 and 5: '||f_getDiff(5,4));
  8    DBMS_OUTPUT.put_line('Diff between 5 and 6: '||f_getDiff(6,5));
  9  end;
 10  /
Diff between 3 and 4: 21.98
Diff between 4 and 5: 28.26
Diff between 5 and 6: 34.54

PL/SQL procedure successfully completed.

SQL>
SQL>








27.3.Function Return
27.3.1.Return Types
27.3.2.Returning values with functions
27.3.3.Return number from a function
27.3.4.Return value from a function
27.3.5.Multiple RETURN Statements
27.3.6.Returning a list based on parameters
27.3.7.Return date value from a function
27.3.8.A pipelined Table Function that returns a PL/SQL type
27.3.9.Return column type
27.3.10.Statements after Return will not be executed
27.3.11.create a function to return a employee record. accept employee numner return all fields.
27.3.12.Return a table collection
27.3.13.Demonstrate returning a record.
27.3.14.Return cursor from function
27.3.15.Return user-defined type