Too many applications

When you run the code below, the following error message appears. I am new to pl / sql (oracle) coding world and I ask for your help for this.

the code:

create or replace package learn is 
function Area(i_rad NUMBER) return NUMBER;
function Area(i_length NUMBER, i_width NUMBER:=3) return NUMBER;
end;
/

Packing case:

create or replace package body learn is 
function Area(i_rad NUMBER) return NUMBER
is
v_pi NUMBER:=3.14;
v number:=to_number(i_rad);
begin
return v_pi * (i_rad ** 2);
end;
function Area(i_length NUMBER, i_width NUMBER:=3) return NUMBER
is
begin
return i_length * i_width;
end;
end learn;

Block plsql

declare
 x number(2):=2;
 y number(2):=5; 
 begin
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(x));
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(x,y));
 end;

Error message: Too many 'AREA' declarations matched this call

+4
source share
2 answers

This is because you have a default value for the second parameter in your param function. If you provide only the parameter, the second function will assume that the second value is 3, and now there are two functions that can be called, and therefore the call failed.

​​, , .

, - null, .

create or replace package learn is
function Area(i_rad NUMBER) return NUMBER;
function Area(i_length NUMBER, i_width NUMBER) return NUMBER;
end;
/

create or replace package body learn is 
function Area(i_rad NUMBER) return NUMBER
is
v_pi NUMBER:=3.14;
v number:=to_number(i_rad);
begin
return v_pi * (i_rad ** 2);
end;
function Area(i_length NUMBER, i_width NUMBER) return NUMBER
is
begin
return i_length * nvl(i_width,3);
end;
end learn;
/

declare
 x number(2):=2;
 y number(2):=5; 
 begin
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(x));
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(x,y));
 end;
 /

, :

declare
 x number(2):=2;
 y number(2):=5; 
 begin
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(i_rad => x));
 DBMS_OUTPUT.put_line('Area (R=3):'||learn.Area(x,y));
 end;
 /
+3

i_width , , number. , :

CREATE OR REPLACE PACKAGE learn IS
    FUNCTION circle_area(i_rad NUMBER) RETURN NUMBER;
    FUNCTION rectangle_area(i_length NUMBER, i_width NUMBER:=3) RETURN NUMBER;
    -- And the same changes in the package body, of course.
END;
/
+2

Source: https://habr.com/ru/post/1666032/


All Articles