How to Fix PLS-00302: Component Must Be Declared in Oracle

Find why a record field or package subprogram is not visible, from misspellings to procedures missing from the package spec.

PLS-00302 is a compile error raised when the part after a dot does not exist in the thing before it: a record field that the record does not have, or a procedure or function that the package specification does not declare. The name before the dot was found, which separates it from PLS-00201. Check the record's columns or the package specification for the right name.

Reproduce the Error

Example:

create table demo_fares (route_code varchar2(10) primary key, fare number);
insert into demo_fares values ('DEL-BOM', 120);
commit;
create or replace package demo_fare_pkg is
  function fare_of (p_route varchar2) return number;
end;
/
create or replace package body demo_fare_pkg is
  function fare_of (p_route varchar2) return number is
    v number;
  begin
    select fare into v from demo_fares where route_code = p_route;
    return v;
  end;
end;
/
declare
  r demo_fares%rowtype;
begin
  select * into r from demo_fares where route_code = 'DEL-BOM';
  dbms_output.put_line(r.fair);                         -- misspelled field
end;
/
begin
  dbms_output.put_line(demo_fare_pkg.get_fare('DEL-BOM'));   -- not in the package spec
end;
/

Output:

Table DEMO_FARES created.

1 row inserted.

Commit complete.

Package DEMO_FARE_PKG compiled

Package Body DEMO_FARE_PKG compiled

  dbms_output.put_line(r.fair);                         -- misspelled field
                         *
ERROR at line 5:
ORA-06550: line 5, column 26:
PLS-00302: component 'FAIR' must be declared
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored

  dbms_output.put_line(demo_fare_pkg.get_fare('DEL-BOM'));   -- not in the package spec
                                     *
ERROR at line 2:
ORA-06550: line 2, column 38:
PLS-00302: component 'GET_FARE' must be declared
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
  • R has the fields ROUTE_CODE and FARE, not FAIR.
  • The package declares FARE_OF, not GET_FARE.

Fix: Use a Declared Component

Example:

set serveroutput on
-- what the package spec declares
select procedure_name from user_procedures
where  object_name = 'DEMO_FARE_PKG' and procedure_name is not null;
declare
  r demo_fares%rowtype;
begin
  select * into r from demo_fares where route_code = 'DEL-BOM';
  dbms_output.put_line(r.fare);
  dbms_output.put_line(demo_fare_pkg.fare_of('DEL-BOM'));
end;
/

Output:

PROCEDURE_NAME
_________________
FARE_OF

120
120

PL/SQL procedure successfully completed.

USER_PROCEDURES lists the subprograms a package makes public.

Other Common Causes

  • A subprogram exists in the package body only: it is private, and callers outside the package cannot see it. Add it to the specification.
  • A local object has the same name as a schema, so schema.object resolves to the wrong thing.
  • A column was renamed, and code still uses the old name through %ROWTYPE.
  • Calling a package of another release or schema, which has no such procedure.

Related Guides

Conclusion

PLS-00302 means the record or package exists, but the named part does not. Check the record's fields or the package specification, and add subprograms to the specification when callers outside the package need them.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted