Oracle PL/SQL - Overloading function: Data type family of parameters

Introduction

Data type families are groups of similar datatypes.

For example, CHAR and VARCHAR2 describe the same kind of textual data, so they belong to the same family.

You can overload only between different families.

The following code is an example of declaring a different datatype family:

Demo

SQL>
SQL> declare--  www. ja  va2s .com
  2     function f_getArea_Nr(i_rad_nr NUMBER, i_prec_nr NUMBER) return NUMBER is
  3          v_pi_nr NUMBER:=3.14;
  4     begin
  5         return trunc(v_pi_nr * (i_rad_nr ** 2),i_prec_nr);
  6     end;
  7     function f_getArea_Nr(i_rad_nr NUMBER, i_ignore_yn VARCHAR2) return NUMBER is
  8          v_pi_nr NUMBER:=3.14;
  9     begin
 10         if i_ignore_yn='Y' and i_rad_nr < 5 then
 11            return 0;
 12         else
 13            return v_pi_nr * (i_rad_nr ** 2);
 14         end if;
 15     end;
 16  begin
 17     DBMS_OUTPUT.put_line('Area (R=3):' ||f_getArea_Nr(3,1));
 18     DBMS_OUTPUT.put_line('Area (R=3):' ||f_getArea_Nr(3,'N'));
 19  end;
 20  /
Area (R=3):28.2
Area (R=3):28.26

PL/SQL procedure successfully completed.

SQL>

Related Topic