ReginaldRey
ReginaldRey

Reputation: 49

Getting PLS-00905 and PLS-00304 errors, not sure why?

I've got the below functions but for some reason I'm getting the above mentioned errors. I've gone through it twice and I'm not sure what the problem is. Can anyone help?

Code is:

    CREATE OR REPLACE PACKAGE DATA_CLEANUP AS 
FUNCTION AVERAGE_GRADE (IN_StudentID IN NUMBER) RETURN NUMBER;
END DATA_CLEANUP;
/
CREATE OR REPLACE PACKAGE BODY DATA_CLEANUP AS
FUNCTION AVERAGE_GRADE (IN_StudentID IN NUMBER) RETURN NUMBER AS
AvgGrade NUMBER;
BEGIN
SELECT AVG(PercentGrade) INTO AvgGrade FROM GRADE
WHERE StudentID = IN_StudentID;
RETURN AvgGrade;
END AVERAGE_GRADE;
END;
/

Upvotes: 0

Views: 561

Answers (1)

Littlefoot
Littlefoot

Reputation: 143103

  • PLS-00905: object is invalid
  • PLS-00304: cannot compile body of without its specification

If table exists (I created a dummy one):

SQL> create table grade as select 15 percentgrade, 1 studentid from dual;

Table created.

Create package specification first ...

SQL> CREATE OR REPLACE PACKAGE DATA_CLEANUP AS
  2    FUNCTION AVERAGE_GRADE (IN_StudentID IN NUMBER) RETURN NUMBER;
  3  END DATA_CLEANUP;
  4  /

Package created.

... and package body next:

SQL> CREATE OR REPLACE PACKAGE BODY DATA_CLEANUP AS
  2    FUNCTION AVERAGE_GRADE (IN_StudentID IN NUMBER) RETURN NUMBER AS
  3      AvgGrade NUMBER;
  4    BEGIN
  5      SELECT AVG(PercentGrade) INTO AvgGrade FROM GRADE
  6      WHERE StudentID = IN_StudentID;
  7      RETURN AvgGrade;
  8    END AVERAGE_GRADE;
  9  END;
 10  /

Package body created.

SQL>

Everything compiles. Does it work?

SQL> select data_cleanup.average_grade(1) result from dual;

    RESULT
----------
        15

SQL>

It works (disregard stupid sample data, but - there are no errors).

If you got errors, you did something wrong. Can't tell what; do you have table grade in your schema?

Upvotes: 1

Related Questions