无法调用在PL / SQL包中定义的函数

时间:2018-11-17 11:10:23

标签: oracle plsql oracle11g

我有这个PL / SQL软件包:

create or replace package palindrome as
    function check_palindrome(num int) return int;
end palindrome;


create or replace package body palindrome as
    function check_palindrome(num int) return int as 
        ans int;
        z int;
        r int;
        rev int;
    begin
        z := num;

        while z > 0 loop
            r := mod(z,10);
            rev := rev*10+r;
            z := floor(z/10);
        end loop;

        if rev=num then
            dbms_output.put_line('the no '||num ||' is a palindrome ');
        else
             dbms_output.put_line('the no '||num ||' is not a palindrome ');
        end if;     
     end check_palindrome;
end palindrome;

我创建了具有一个功能check_palindrome()的上述程序包,但是当我尝试使用

调用该功能时
begin
    palindrome.check_palindrome(343);
end;

我收到此错误

Error report -
ORA-06550: line 2, column 5:
PLS-00221: 'CHECK_PALINDROME' is not a procedure or is undefined
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored

为什么会出现此错误?包主体已成功编译,但是在调用函数时出现此错误。

2 个答案:

答案 0 :(得分:3)

您已经声明了一个FUNCTION,该函数返回一个值,但是您像调用PROCEDURE一样调用了它,因此您需要:

alpha

答案 1 :(得分:1)

您的程序实际上没有返回任何内容,并且在将结果显示到屏幕上时似乎没有任何纠正的价值。相反,您应该将其变成一个过程:

create or replace package palindrome as
    procedure check_palindrome(num int) ;
end palindrome;


create or replace package body palindrome as
    procedure check_palindrome(num int)  as 
        ans int;
        z int;
        r int;
        rev int;
    begin
        z := num;

        while z > 0 loop
            r := mod(z,10);
            rev := rev*10+r;
            z := floor(z/10);
        end loop;

        if rev=num then
            dbms_output.put_line('the no '||num ||' is a palindrome ');
        else
             dbms_output.put_line('the no '||num ||' is not a palindrome ');
        end if;     
     end check_palindrome;
end palindrome;

然后您可以成功调用它:

begin
    palindrome.check_palindrome(343);
end;