PLS-00201 – identifier must be declared, passing a collection to procedure

A type declared locally to a procedure and another type declared locally to another procedure with exactly the signature are not the same types and you cannot pass one to the other. You need to create the type externally to the procedures rather than internally.

Also, you cannot use the type in the signature for the package when it is not declared except internally to the procedure which is declared in the body of the package.

create or replace package PACK_DW_TEMP  
as
  TYPE error IS RECORD(
    cod_error       NUMBER,
    descr_error     VARCHAR2(100)
  );

  type l_error is table of error;
  procedure A;
  procedure B (error_list in out l_error);
  
end PACK_DW_TEMP;
/

and

create or replace package body PACK_DW_TEMP
as
  procedure A
  as
    error_list  l_error := l_error(); 
  begin
    error_list.EXTEND(2);
    error_list(1).cod_error   := 1;
    error_list(1).descr_error := 'DESCR1';
    error_list(2).cod_error   := 2;
    error_list(2).descr_error := 'DESCR2';
    
    B(error_list);

    FOR i IN 1 .. error_list.COUNT LOOP
      DBMS_OUTPUT.PUT_LINE(
        error_list(i).cod_error || ': ' || error_list(i).descr_error
      );
    END LOOP;
  end;

  procedure B ( error_list in out l_error )
  as
  begin
    error_list.EXTEND;
    error_list(error_list.COUNT).cod_error   := 99;
    error_list(error_list.COUNT).descr_error := 'DESCR99';
  end;
end;    
/

Then you can call it using:

BEGIN
  PACK_DW_TEMP.A();
END;
/

Which outputs:

1: DESCR1
2: DESCR2
99: DESCR99

db<>fiddle here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top