暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 查询偶尔返回ORA-00932的问题: 不一致的数据类型: 预期-得到-

askTom 2018-02-08
1420

问题描述

亲爱的汤姆继任者,

我有一个问题,我无法追踪,因为它似乎是随机发生的。
首先,我使用:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for Solaris: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production


问题如下:
plsql包中有一个函数。这个函数运行一个很大的选择,并调用其他函数,但没有什么特别的。

有时此函数返回一个
ORA-00932: inconsistent datatypes: expected - got -
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:


函数使用以下类型:

CREATE OR REPLACE TYPE STRINGLIST_O AS OBJECT 
(
  text VARCHAR2(4000)
)
/

CREATE OR REPLACE TYPE STRINGLIST_T as TABLE of STRINGLIST_O
/

CREATE OR REPLACE TYPE STRINGLIST_LIST_T as TABLE of STRINGLIST_T
/

In order to reproduce this, I executed

create table t1 (val varchar2(4000), room_uid integer )
/  

insert into table t1 (val, room_uid ) values ('test text, 621)
/

commit
/

-- the following construct is basically what make sthe procedure sometimes(!) fail.
-- of course the thing in real life is a bit more complicated.
with X as
( select stringlist_t(stringlist_o(val)) t1_val, room_uid from t1 )
select room_uid,
       cast(collect(t1_val) as stringlist_list_t) t1_val_collection
  from X
  group by room_uid;


问题是,即使是简单的事情有时也会失败,有时却不会。如果我有一个会话 (由于不清楚的原因) 原始函数调用失败,那么此选择的后续执行也将失败。关闭连接并重新打开它 “解决” 了到目前为止的问题,因为现在完全相同的select现在可以工作 (直到下一次 “偶然” 失败。

即使上面提到的选择失败,下面的选择可能仍然有效:

select room_uid, CAST(COLLECT(t1_val) AS STRINGLIST_LIST_T) from(
SELECT room_uid ,stringlist_t(stringlist_o(val)) t1_val FROM t1 
)GROUP BY room_uid;


我的问题是,你知道什么会导致这个选择的偶尔失败,或者你有什么建议我应该检查。

谢谢,
约亨

PS: 由于每次执行都不会发生这种情况,因此提供的livesql链接可能不会显示问题。

专家解答

抱歉,我不能复制...

select * from v$version;

BANNER                                                                         
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production   
PL/SQL Release 11.2.0.4.0 - Production                                         
CORE 11.2.0.4.0 Production                                                     
TNS for Linux: Version 11.2.0.4.0 - Production                                 
NLSRTL Version 11.2.0.4.0 - Production 

create or replace type stringlist_o as object( text varchar2(4000) )  
/

create or replace type stringlist_t as table of stringlist_o 
/

create or replace type stringlist_list_t as table of stringlist_t 
/

create table t1 (val varchar2(4000), room_uid integer ) ;

insert into t1 (val, room_uid ) values ('test text', 621 ) ;
commit ;

with X as 
( select stringlist_t(stringlist_o(val)) t1_val, room_uid from t1) 
select room_uid, 
       cast( collect(t1_val) as stringlist_list_t) t1_val_collection 
 from X 
 group by room_uid;

ROOM_UID   T1_VAL_COLLECTION           
       621 oracle.sql.ARRAY@771d8c9f   


我看到你在索拉里斯。因此,您可能遇到了特定于平台的错误。无论如何,请联系支持人员寻求帮助。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论