The PLS-00302: component must be declared error occurs when the component of an object is used in the PL/SQL code but not declared in the oracle database object. The data base objects such as type, package, table, cursor may contain member components. If the components are not declared in the respective database objects but referenced in the oracle PL/SQL code, the error PLS-00302: component must be declared will be thrown.

The oracle data base package contains components such as functions, procedures, triggers, variables. The package components are referenced by the name of the type or package. If the package components are not declared either in package declaration or package body but used in the PL/SQL code, the error PLS-00302: component must be declared will be thrown.



Exception

The stack trace for the exception would look like this. The exception would be thrown if the component is not declared in the database object. When the component reference is used in Oracle PL/SQL language, an error would be thrown.

Error report -
ORA-06550: line 4, column 17:
PLS-00302: component 'PUT_LINE1' must be declared
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:


Cause

The database objects such as type, package, table, cursor can contain multiple components. The database container objects are used to identify these member elements. If you refer to a member component that isn’t declared inside the object but you attempt to call it, an exception would be thrown. The member component is not available. As a result, the database object was unable to provide the member component.



Solution 1

The component is not declared, which is why this exception is thrown. If an error happens when trying to call some system functions. This is most likely due to a misspelled function, procedure, or trigger name. This error would be fixed if the spelling in the code is corrected.

declare
    empname varchar2(10) :='yawin';
begin
    dbms_output.put_line1(empname);
end;

Exception

Error report -
ORA-06550: line 4, column 17:
PLS-00302: component 'PUT_LINE1' must be declared
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored

Solution

declare
    empname varchar2(10) :='yawin';
begin
    dbms_output.put_line(empname);
end;

Output

yawin
PL/SQL procedure successfully completed.


Solution 2

If you call a member component that isn’t specified in the database type, the type object won’t know what to do with the member variable’s value. The member variable is not declared in the code or the member variable name is misspelled. If a member variable isn’t declared, it can’t be used. declare the variable as a type variable. If the variable name is misspelled, make the appropriate changes.

create or replace type student is object
(
name varchar2(100)
);

set serveroutput on
declare
 st student;
begin
    st := student(1,'Yawin');
    dbms_output.put_line(st.id);
end;

Exception

Error report -
ORA-06550: line 4, column 11:
PLS-00306: wrong number or types of arguments in call to 'STUDENT'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
ORA-06550: line 5, column 29:
PLS-00302: component 'ID' must be declared
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"

Solution

create or replace type student is object
(
id numeric(5),
name varchar2(100)
);

set serveroutput on
declare
 st student;
begin
    st := student(1,'Yawin');
    dbms_output.put_line(st.id);
end;

Output

1
PL/SQL procedure successfully completed.


Solution 3

If package members such as function, procedure, and triggers are not declared and used in PL/SQL code, an exception would be thrown. Add a member function, procedure, or trigger definition if it is absent or the declaration isn’t available. If the spelling of a member’s name is incorrect, change it.

CREATE PACKAGE MYPACKAGE AS 
   PROCEDURE PRINTNAME; 
END MYPACKAGE;

CREATE OR REPLACE PACKAGE BODY MYPACKAGE AS  
   PROCEDURE PRINTNAME IS     
   BEGIN 
      dbms_output.put_line('Yawin'); 
   END PRINTNAME; 
END MYPACKAGE; 

DECLARE  
BEGIN 
   MYPACKAGE.PRINTNAME1; 
END; 

Exception

Error report -
ORA-06550: line 3, column 14:
PLS-00302: component 'PRINTNAME1' must be declared
ORA-06550: line 3, column 4:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.

Solution

DECLARE  
BEGIN 
   MYPACKAGE.PRINTNAME; 
END; 

Output

Yawin
PL/SQL procedure successfully completed.


Solution 4

If the variable is declared as an array or list, the elements of the array or list should be invoked. If the array variable is used as a single object variable, the exception will be thrown. The index can be used to refer to the value in the array variable. The error may be fixed by indexing the variable.

create or replace type student is object
(
id numeric(5),
name varchar2(100)
);
declare
 TYPE studentarr IS TABLE OF student INDEX BY PLS_INTEGER;
 st studentarr;
begin
    st := student(1,'Yawin');
   dbms_output.put_line(st.id);
end;

Exception

Error report -
ORA-06550: line 5, column 11:
PLS-00382: expression is of wrong type
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
ORA-06550: line 6, column 28:
PLS-00302: component 'ID' must be declared
ORA-06550: line 6, column 4:
PL/SQL: Statement ignored

Solution

set serveroutput on
declare
 TYPE studentarr IS TABLE OF student INDEX BY PLS_INTEGER;
 st studentarr;
begin
    st(1) := student(1,'Yawin');
   dbms_output.put_line(st(1).id);
end;

Output

1
PL/SQL procedure successfully completed.


Solution 5

There’s a chance you don’t have enough permission to execute the objects. If the permission isn’t available, you’ll have to give it to the objects. You may need to contact the database administrator to get this permission. You can access the components if you have the database object permission.

grant execute on MYPACKAGE.PRINTNAME to yawin;



Leave a Reply