简体   繁体   English

PLS-00201 - 必须声明标识符,将集合传递给过程

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

I'm trying to pass a collection to procedure, but when I compile the package, I'll get this message:"PLS-00201 – identifier must be declared".我正在尝试将集合传递给过程,但是当我编译包时,我会收到以下消息:“PLS-00201 – 必须声明标识符”。 this is my code:这是我的代码:

create or replace package PACK_DW_TEMP  
as

procedure A (.......);
--
procedure B (error_list in out l_error);

end PACK_DW_TEMP; 

In the package body I've created the collection in the procedure A and passed it to procedure B在包体中,我在过程 A 中创建了集合并将其传递给过程 B

create or replace package body PACK_DW_TEMP
as

procedure A ( ........ )
as
begin
declare

     
    
    type error IS RECORD(
            cod_error       NUMBER,
            descr_error     VARCHAR2(100)
            );

    type l_errori is table of error;
    error_list  l_error := l_error(); 
begin
  procedure B(error_list);
end;
end;

Into procedure B:进入程序B:

procedure B ( error_list in out l_error )
as
begin
declare
    i    NUMBER;
    
    type err IS RECORD(
            cod_error       NUMBER,
            descr_error     VARCHAR2(100)
            );

    type l_err is table of err;
    err_list  l_err := l_err(); 

begin
     i := 0;
     for i in 1..5 loop
      err_list(i).cod_err := error_list(i).cod_error;
      err_list(i).descr_err := error_list(i).descr_error;
     end loop;
end;

end;    

My target is to pass the collection to procedure B and to assegn values to the new collection.我的目标是将集合传递给过程 B 并将值分配给新集合。

You're defining a type called l_err in the package body but in procedure B you're trying to use a type called l_error .您在包体中定义了一个名为l_err的类型,但在过程B您尝试使用一个名为l_error的类型。 Also, you have to define l_error in the package spec, prior to its first use:此外,在首次使用之前,您必须在包规范中定义l_error

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

  type l_error is table of err;

  procedure A (.......);
  --
  procedure B (error_list in out l_error);  
end PACK_DW_TEMP; 

and remove the definitions of type_err , l_errori , and l_err from the package body.并从包体中删除type_errl_erroril_err的定义。

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 db<> 在这里摆弄

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM