SQL 为什么 PLS-00382:表达式类型错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9472048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why PLS-00382: expression is of wrong type?
提问by Felipe Almeida
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:
但是,(这已经花费了我 4 个多小时),当我尝试像这样运行它时:
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)
我收到以下错误消息:PLS-00382: expression is of wrong type。(在我将函数返回值分配给 RetVal 变量的那一行)
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???
我的意思是,该函数返回的RECORD
类型与我声明的变量完全相同!!我在这里错过了什么???
Thanks (and a few REP points) in advance.!
提前致谢(和一些 REP 点)。!
回答by Ben
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?
您尚未提供如何创建全局类型,但如果您没有在包中创建,则提供的语法不正确;你确定编译了吗?
回答by Stephen ODonnell
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:
声明框中的类型与函数中使用的类型不同。它可能看起来一样,但对于 PLSQL 编译器来说却是不同的。如果你只是在声明块中使用已经定义的类型,它可能会起作用,例如:
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;
回答by Amir Pashazadeh
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.
我不确定,但您在许多其他语言(例如 Pascal 或 Java)中遇到的情况似乎相同,假设您在 Java 中声明了两个具有完全相同字段和方法的不同类,它们是否可以赋值?不。
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.
我相信你的类型只是看起来一样,但它们是一样的。您必须使用在调用代码块中定义的类型。