Felipe
Felipe

Reputation: 11907

Why PLS-00382: expression is of wrong type?

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.!

Upvotes: 0

Views: 29495

Answers (3)

Ben
Ben

Reputation: 52923

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?

Upvotes: 6

Amir Pashazadeh
Amir Pashazadeh

Reputation: 7322

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.

Upvotes: 1

Stephen ODonnell
Stephen ODonnell

Reputation: 4466

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;

Upvotes: 3

Related Questions