简体   繁体   English

为什么是PLS-00382:表达式的类型错误?

[英]Why PLS-00382: expression is of wrong type?

I have the following custom RECORD TYPE : 我有以下自定义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 . 我收到以下错误消息: PLS-00382:表达式类型错误 (on the line that I assign the function returned value to the RetVal variable) (在我将函数返回的值分配给RetVal变量的行上)

I mean, the function returns a RECORD which is of the exact same type as the variable I've declared!! 我的意思是,该函数返回一个RECORD ,其类型与我声明的变量完全相同! What am I missing here??? 我在这里想念什么???

Thanks (and a few REP points) in advance.! 预先感谢(和一些REP要点)!

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... 目前,您的commit没有执行任何操作...

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? 您确定它已编译吗?

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. 它看起来可能相同,但是到PLSQL编译器是不同的。 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;

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? 我不确定,但是在许多其他语言(例如Pascal或Java)中似乎遇到了同样的事情,假设您用完全相同的字段和方法在Java中声明了两个不同的类,它们是否可分配? 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. 您必须使用在调用代码块中定义的类型。

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

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