最近資料庫從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 CLOB30/13 PL/SQL: SQL Statement ignored898/13 PL/SQL: ORA-00932: inconsistent datatypes: expected - got CLOB898/13 PL/SQL: SQL Statement ignored
2、分析與解決
--記得當前伺服器下資料庫並沒有使用任何CLOB資料類型,卻返回CLOB類型了,我懵!--還是搜尋了資料庫中是否存在,一個也沒有找到SQL> select * from v$version where rownum<2;BANNER----------------------------------------------------------------Oracle Database 10g Release 10.2.0.3.0 - 64bit ProductionSQL> 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 ProductionSQL> desc wmsys.wm_concatFUNCTION 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 ProductionSQL> desc wmsys.wm_concatFUNCTION 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環境),僅僅是執行SQLSQL> select * from t8; ID VAL---------- -------------------- 1 LINUX 1 SOLARIS 2 ORACLE 2 MYSQLSQL> 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 OFFICESQL> 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 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 負載平衡測試(結合伺服器端與用戶端)
Oracle RAC 伺服器端串連負載平衡(Load Balance)
Oracle RAC 用戶端串連負載平衡(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 監聽器密碼(LISTENER)
配置ORACLE 用戶端串連到資料庫
有關基於使用者管理的備份和備份恢複的概念請參考
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 密碼檔案
Oracle 參數檔案
Oracle 聯機重做記錄檔(ONLINE LOG FILE)
Oracle 控制檔案(CONTROLFILE)
Oracle 歸檔日誌
Oracle 復原(ROLLBACK)和撤銷(UNDO)
Oracle 資料庫執行個體啟動關閉過程
Oracle 10g SGA 的自動化管理
Oracle 執行個體和Oracle資料庫(Oracle體繫結構)