Oracle PL/SQL - Overloading function: Number of parameters

Introduction

The following example shows how you can declare a different number of parameters:

Demo

SQL>
SQL> declare--  www  .j a  v a  2  s .  co  m
  2        function f_getArea_Nr(i_rad_nr NUMBER)
  3           return NUMBER
  4        is
  5             v_pi_nr NUMBER:=3.14;
  6       begin
  7           return v_pi_nr * (i_rad_nr ** 2);
  8        end;
  9
 10         function f_getArea_Nr(i_length_nr NUMBER, i_width_nr NUMBER)
 11            return NUMBER
 12         is
 13        begin
 14            return i_length_nr * i_width_nr;
 15         end;
 16  begin
 17       DBMS_OUTPUT.put_line('Area (R=3):'||f_getArea_Nr(3));
 18       DBMS_OUTPUT.put_line('Area (2x3):'||f_getArea_Nr(2,3));
 19  end;
 20  /
Area (R=3):28.26
Area (2x3):6

PL/SQL procedure successfully completed.

SQL>

Here, the code has two functions with the same name, but the first one has a single parameter and the second has double parameters.

Related Topic