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體系結構) 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM