Why PLS-00382: expression is of wrong type?

半世苍凉 提交于 2021-02-08 10:59:55

问题


I have the following custom RECORD TYPE:

TYPE TB48_RECTYPE IS RECORD ( 
                             codpo varchar2(5 BYTE),
                             codco varchar2(5 BYTE),
                             quadr varchar2(5 BYTE),
                             espec varchar2(5 BYTE),
                             aperf varchar2(5 BYTE),
                             subes varchar2(5 BYTE),
                             datin date);

And now a function that returns the exact same type.

function retorna_infos_tabela_48(i_nip in varchar2) return TB48_RECTYPE is

retorno_REC TB48_RECTYPE;


begin
    select m.CODPO,
           m.CODCO,
           m.QUADR,
           m.ESPEC,
           m.APERF,
           m.SUBES,
           m.DATIN 
    into retorno_REC
    from TB48_M m
    where m.NRO = i_nip;

    return retorno_REC;

end retorna_infos_tabela_48; 

However, (and this has cost me more than 4 hours already), when I try and run it like this:

    DECLARE 
    TYPE TB48_RECTYPE IS RECORD (
                             codpo varchar2(5 BYTE),
                             codco varchar2(5 BYTE),
                             quadr varchar2(5 BYTE),
                             espec varchar2(5 BYTE),
                             aperf varchar2(5 BYTE),
                             subes varchar2(5 BYTE),
                             datin date);
  RetVal TB48_RECTYPE;
  I_NIP VARCHAR2(200);

  BEGIN 
    I_NIP := '88888888';
    RetVal := RETORNA_INFOS_TABELA_48 ( I_NIP );
    COMMIT; 
  END;

I get the following error message: PLS-00382: expression is of wrong type. (on the line that I assign the function returned value to the RetVal variable)

I mean, the function returns a RECORD which is of the exact same type as the variable I've declared!! What am I missing here???

Thanks (and a few REP points) in advance.!


回答1:


I suspect your problem is that you attempting to place a globally declared type into a locally declared one.

I think if you change your procedure to the following it should work.

declare

  RetVal TB48_RECTYPE;
  i_nip varchar2(200);

begin

   i_nip := '86583557';
   RetVal := USERTEMPOS.PKG_ESTRANG_NOVA.RETORNA_INFOS_TABELA_48 ( I_NIP );

   commit;

end;

Currently your commit is doing nothing...

You haven't provided how you created your global type, but if you didn't do it in a package then the provided syntax is incorrect; are you sure it compiled?




回答2:


The type in your declare box is not the same as the type used in the function. It may look the same, but to the PLSQL compiler is different. If you just use the already defined type in the declare block, it will probably work, eg:

declare
  RetVal TB48_RECTYPE;
  I_NIP VARCHAR2(200);

BEGIN 
  I_NIP := '86583557';
  RetVal := USERTEMPOS.PKG_ESTRANG_NOVA.RETORNA_INFOS_TABELA_48 ( I_NIP );
  COMMIT; 
END;



回答3:


I'm not sure, but it seems the same thing you encounter in many other languages (such as Pascal or Java), Suppose you declare two different classes in Java with the exact same fields and methods, are they assignable? Nope.

I believe your types just look the same, but they are the same. You must use the type you have defined in calling code block.



来源:https://stackoverflow.com/questions/9472048/why-pls-00382-expression-is-of-wrong-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!