ORA-00932: inconsistent datatypes: expected - got CLOB

      近期数据库从10.2.0.3升级到了10.2.0.5之后,一些对象无法编译通过。查看了这些对象主要表如今之前写法不严格的SQL语法导致了这些package无法成功编译,诸如select查询列中不能使用混淆的列名称等。

另外一个比較表现突出的是返回ORA-00932: inconsistent datatypes: expected - got CLOB错误。即不一致的数据类型,获得CLOB数据类型。以下是这个问题的症状及对策。

 

1、故障现象

SQL> alter package bo_trd_trade_relink_pkg compile body;

Warning: Package Body altered with compilation errors.

SQL> show errors;
Errors for PACKAGE BODY BO_TRD_TRADE_RELINK_PKG:

LINE/COL ERROR
-------- -----------------------------------------------------------------
30/13    PL/SQL: ORA-00932: inconsistent datatypes: expected - got CLOB
30/13    PL/SQL: SQL Statement ignored
898/13   PL/SQL: ORA-00932: inconsistent datatypes: expected - got CLOB
898/13   PL/SQL: SQL Statement ignored

2、分析与解决

--记得当前server下数据库并没有使用不论什么CLOB数据类型,却返回CLOB类型了,我懵。
--还是搜索了数据库中是否存在,一个也没有找到
SQL> select * from v$version where rownum<2;

BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

SQL> select data_type from dba_tab_columns where data_type like '%LOB%' and owner='GOEX_ADMIN';

no rows selected

--在错误提示地方,如30行处发现了为select 查询列使用了wm_concat函数。尝试注视该列,Pckage编译成功,看来是这个函数是罪魁祸首
--关于这个函数在10.2.0.3的表现为返回为VARCHAR2数据类型,例如以下: 
SQL> select * from v$version where rownum<2;

BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

SQL> desc wmsys.wm_concat
FUNCTION wmsys.wm_concat RETURNS VARCHAR2
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 P1                             VARCHAR2                IN

--而10.2.0.5表现为返回的CLOB数据类型 
SQL> select * from v$version where rownum<2;

BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.5.0 - 64bit Production

SQL> desc wmsys.wm_concat
FUNCTION wmsys.wm_concat RETURNS CLOB
 Argument Name                  Type                    In/Out Default?

------------------------------ ----------------------- ------ -------- P1 VARCHAR2 IN --Author : Leshami --Blog : http://blog.csdn.net/leshami --因为返回类型不一致导致了package在新环境中无法成功编译 原因:lob字段不能用做group by,而union中须要使用group by过滤反复记录。所以无法编译成功 解决方式: a、为这个select 查询列使用了to_char函数来进行转换(wm_concat(col_name)) b、或者改动union 为union all --以下给一个演示样例供大家參考(10.2.0.5环境)。不过运行SQL SQL> select * from t8; ID VAL ---------- -------------------- 1 LINUX 1 SOLARIS 2 ORACLE 2 MYSQL SQL> select * from t9; ID VAL ---------- -------------------- 3 OFFICE --单独使用时没有不论什么异常 SQL> select id,wm_concat(val) new_val from t8 group by id; ID NEW_VAL ---------- ------------------------------ 1 LINUX,SOLARIS 2 ORACLE,MYSQL --使用union时出现ORA-00932错误 SQL> select id,wm_concat(val) new_val from t8 group by id 2 union 3 select id,wm_concat(val) new_val from t9 group by id; select id,wm_concat(val) new_val from t8 group by id * ERROR at line 1: ORA-00932: inconsistent datatypes: expected - got CLOB --通过改动union为union all或者使用to_char类解决 SQL> select id,wm_concat(val) new_val from t8 group by id 2 union all 3 select id,wm_concat(val) new_val from t9 group by id; ID NEW_VAL ---------- ------------------------------ 1 LINUX,SOLARIS 2 ORACLE,MYSQL 3 OFFICE SQL> select id,to_char(wm_concat(val)) new_val from t8 group by id 2 union select id, to_char(wm_concat(val)) new_val from t9 group by id; ID NEW_VAL ---------- ------------------------------ 1 LINUX,SOLARIS 2 ORACLE,MYSQL 3 OFFICE

                  
3、Metalink上的相关文档(ID 1300595.1,ID 1336219.1)
--是一个内部函数,不建议使用

Symptoms

In releases 10.2.0.5 and 11.2.0.2, creating a view using the WMSYS.WM_CONCAT function fails. 

In releases 10.2.0.4, 11.1.0.7 and 11.2.0.1, the view compiles successfully.

 

Cause

The datatype returned from WMSYS.WM_CONCAT function changed from VARCHAR2 to CLOB in releases 10.2.0.5 and 11.2.0.2.

In 10.2.0.4 / 11.1.0.7 / 11.2.0.1 it returns VARCHAR2
SQL> desc wmsys.wm_concat;
FUNCTION wmsys.wm_concat RETURNS VARCHAR2 <<<<<<<<<<<<<<<Argument Name           Type                     In/Out   Default?


----------------------- ------------------------ -------- ---------
P1                      VARCHAR2                 IN


In 10.2.0.5 / 11.2.0.2 it returns CLOB
SQL> desc wmsys.wm_concat;
FUNCTION wmsys.wm_concat RETURNS CLOB <<<<<<<<<<<<<<<Argument Name           Type                     In/Out   Default?


----------------------- ------------------------ -------- ---------
P1                      VARCHAR2                 IN

 

Solution

This is not a bug.

The function WMSYS.WM_CONCAT is an internal undocumented function which is installed/uninstalled as part of the Workspace Manager feature of Oracle Database. It is internally used in a number of Workspace Manager views. It is not meant to be used by customers directly, and could be changed/updated without notice by Oracle Development. Do not use the WMSYS.WM_CONCAT view in your application.

 

Oracle&nbsp;牛鹏社    Oracle DBsupport

很多其它參考

有关Oracle RAC请參考
     使用crs_setperm改动RAC资源的全部者及权限
     使用crs_profile管理RAC资源配置文件
     RAC 数据库的启动与关闭
     再说 Oracle RAC services
     Services in Oracle Database 10g
     Migrate datbase from single instance to Oracle RAC
     Oracle RAC 连接到指定实例
     Oracle RAC 负载均衡測试(结合server端与client)
     Oracle RAC server端连接负载均衡(Load Balance)
     Oracle RAC client连接负载均衡(Load Balance)
     ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
     ORACLE RAC 监听配置 (listener.ora tnsnames.ora)
     配置 RAC 负载均衡与故障转移
     CRS-1006 , CRS-0215 故障一例 
     基于Linux (RHEL 5.5) 安装Oracle 10g RAC
     使用 runcluvfy 校验Oracle RAC安装环境

有关Oracle 网络配置相关基础以及概念性的问题请參考:
     配置非默认端口的动态服务注冊
     配置sqlnet.ora限制IP訪问Oracle
     Oracle 监听器日志配置与管理
     设置 Oracle 监听器password(LISTENER)
     配置ORACLE client连接到数据库

有关基于用户管理的备份和备份恢复的概念请參考
     Oracle 冷备份
     Oracle 热备份
     Oracle 备份恢复概念
     Oracle 实例恢复
     Oracle 基于用户管理恢复的处理
     SYSTEM 表空间管理及备份恢复
     SYSAUX表空间管理及恢复
     Oracle 基于备份控制文件的恢复(unsing backup controlfile)

有关RMAN的备份恢复与管理请參考
     RMAN 概述及其体系结构
     RMAN 配置、监控与管理
     RMAN 备份具体解释
     RMAN 还原与恢复
     RMAN catalog 的创建和使用
     基于catalog 创建RMAN存储脚本
     基于catalog 的RMAN 备份与恢复
     RMAN 备份路径困惑
     使用RMAN实现异机备份恢复(WIN平台)
     使用RMAN迁移文件系统数据库到ASM
     linux 下RMAN备份shell脚本
     使用RMAN迁移数据库到异机

有关ORACLE体系结构请參考
     Oracle 表空间与数据文件
     Oracle password文件
     Oracle 參数文件
     Oracle 联机重做日志文件(ONLINE LOG FILE)
     Oracle 控制文件(CONTROLFILE)
     Oracle 归档日志
     Oracle 回滚(ROLLBACK)和撤销(UNDO)
     Oracle 数据库实例启动关闭过程
     Oracle 10g SGA 的自己主动化管理
     Oracle 实例和Oracle数据库(Oracle体系结构) 

posted @ 2017-05-20 13:36  clnchanpin  阅读(4031)  评论(0编辑  收藏  举报