Forward Declaration of Procedures and Functions in Packages [message #192357] |
Tue, 12 September 2006 01:05  |
srinivasocp
Messages: 91 Registered: December 2005 Location: INDIA
|
Member |
|
|
Hi All,
CREATE OR REPLACE PACKAGE emp_test1 IS
g_variable number(10);
PROCEDURE emp_proc1 (v_empno NUMBER);
PROCEDURE emp_proc2 (v_empno NUMBER);
END;
CREATE OR REPLACE PACKAGE BODY emp_test1 IS
function chk_empno(v_empno number) Return boolean;
PROCEDURE emp_proc1(v_empno NUMBER) IS
BEGIN
chk_empno(v_empno);
INSERT INTO emp(empno) VALUES (v_empno);
END;
function chk_empno(v_empno number) Return boolean is
begin
if v_empno<7000 then
raise_application_error(-20001,'Missed');
else
return(true);
end if;
end;
PROCEDURE emp_proc2(v_empno NUMBER) IS
BEGIN
INSERT INTO emp(empno) VALUES (v_empno);
END;
END emp_test1;
ERROR IS:-
Quote: |
LINE/COL ERROR
-------- ---------------------------------------------------
5/3 PLS-00221: 'CHK_EMPNO' is not a procedure or is undefined
|
Why this error is coming . I have define the function before hand i.e., Forward declaration done.Even if i define the finction fully first and then calling it in the procedure also same error is coming. Please let me know how to avert this error.
Any help is highly appreciated.
Regards
Srini..
Srini..
|
|
|
Re: Forward Declaration of Procedures and Functions in Packages [message #192361 is a reply to message #192357] |
Tue, 12 September 2006 01:16   |
 |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
chk_empno is not defined the way it is used in emp_proc1. In emp_proc1 you use the procedure chk_empno. At least, that's what Oracle's compiler thinks because it does not return any value. You have got to do something with the value returned from chk_empno. Try this instead:
CREATE OR REPLACE PACKAGE BODY emp_test1
IS
FUNCTION chk_empno(v_empno number) RETURN BOOLEAN;
PROCEDURE emp_proc1(v_empno NUMBER)
IS
v_dummy BOOLEAN;
BEGIN
-- You need to catch THE RETURN VALUE because otherwise 'chk_empno'
-- will be interpreted as a procedure -> undefined!
v_dummy := chk_empno(v_empno);
INSERT INTO emp(empno) VALUES (v_empno);
END;
FUNCTION chk_empno(v_empno number)
RETURN BOOLEAN
IS
BEGIN
if v_empno<7000 then
raise_application_error(-20001,'Missed');
else
return(true);
end if;
END;
PROCEDURE emp_proc2(v_empno NUMBER) IS
BEGIN
INSERT INTO emp(empno) VALUES (v_empno);
END;
END emp_test1;
/
It's a minor error. You were on the right track...
MHE
[Updated on: Tue, 12 September 2006 01:16] Report message to a moderator
|
|
|
|