Home » SQL & PL/SQL » SQL & PL/SQL » Forward Declaration of Procedures and Functions in Packages
icon8.gif  Forward Declaration of Procedures and Functions in Packages [message #192357] Tue, 12 September 2006 01:05 Go to next message
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 Go to previous messageGo to next message
Maaher
Messages: 7062
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

Re: Forward Declaration of Procedures and Functions in Packages [message #192383 is a reply to message #192361] Tue, 12 September 2006 02:17 Go to previous message
srinivasocp
Messages: 91
Registered: December 2005
Location: INDIA
Member
Thanks Maaher.
Previous Topic: Question about using Max
Next Topic: splliting the string
Goto Forum:
  


Current Time: Sat Dec 03 01:30:54 CST 2016

Total time taken to generate the page: 0.08253 seconds