WMSYS.WM_CONCAT函数返回结果为CLOB引起视图无法创建

WMSYS.WM_CONCAT函数在11.2.0.2和10.2.0.5之后和版本返回结果为CLOB类型,会导致一些兼容性问题,这是1个比较常见的问题,但我之前未曾遇到,所以也害我折腾了大半天,在此mark一下。

问题描述:

在做exp/imp,新库imp时发现1个视图异常(IMP-00041: Warning: object created with compilation warnings)
手工创建,创建不了,报:ORA-00932: inconsistent datatypes: expected - got CLOB
但是旧库是正常的。


新库(imp导入的库)环境:


$ uname -a
Linux 601cluster 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux


SQL> select * from V$version;


BANNER
--------------------------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production


SQL> select action,comments from registry$history;


ACTION                         COMMENTS
------------------------------ -----------------
VIEW RECOMPILE                 view recompilation
UPGRADE                        Upgraded from 10.2.0.1.0
APPLY                          PSU 10.2.0.5.4




旧库(exp导出的库)环境:
$ uname -a
Linux pera205 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
SQL> select * from V$version;


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


问题SQL如下:


SQL较长,为了可读性,减掉了许多,但是报错效果是一样的。


create or replace view xxxx01 as
select
  distinct( k.KNOWLEDGE_ID),
  k.AUTHORID,
  (select WMSYS.WM_CONCAT(kwt.workbag_id)
     from km_workbag_knowledge kwt where kwt.object_type = 3
      and kwt.knowledge_id=k.knowledge_id) as topicID
  from KM_Knowledge K
  where
  k.param4 = 2
  and k.param5 = 0 and k.current_version='1'
  order by k.knowledge_id
;


去掉含有distinct的列,可以创建成功,如下:


create or replace view xxxx02 as
select
  k.AUTHORID,
  (select WMSYS.WM_CONCAT(kwt.workbag_id)
     from km_workbag_knowledge kwt where kwt.object_type = 3
      and kwt.knowledge_id=k.knowledge_id) as topicID
  from KM_Knowledge K
  where
  k.param4 = 2
  and k.param5 = 0 and k.current_version='1'
  order by k.knowledge_id
;


去掉有CLOB列也可以创建成功,如下:


create or replace view xxxx03 as
select
  distinct( k.KNOWLEDGE_ID),
  k.AUTHORID
  from KM_Knowledge K
  where
  k.param4 = 2
  and k.param5 = 0 and k.current_version='1'
  order by k.knowledge_id
;


表中的数据:
SQL>  select count(*) from km_workbag_knowledge;


  COUNT(*)
----------
      1536


SQL> select count(*) from KM_Knowledge;                               


  COUNT(*)
----------
     64449


单独执行以下SQL:
select WMSYS.WM_CONCAT(kwt.workbag_id)
     from km_workbag_knowledge kwt,KM_Knowledge K where kwt.object_type = 3
      and kwt.knowledge_id=k.knowledge_id
通过PL/SQL执行,从结果的显示来看,旧库中该结果并没有转换成CLOB型,新库转换成了CLOB


在旧库中执行以下SQL:
将后面字段手工变为CLOB
create or replace view xxxx04 as
select
  distinct( k.KNOWLEDGE_ID),
  k.AUTHORID,
  to_clob(
  (select WMSYS.WM_CONCAT(kwt.workbag_id)
     from km_workbag_knowledge kwt where kwt.object_type = 3
      and kwt.knowledge_id=k.knowledge_id)) as topicID
  from KM_Knowledge K
  where
  k.param4 = 2
  and k.param5 = 0 and k.current_version='1'
  order by k.knowledge_id
;
同样报下面的错:
ORA-00932: 数据类型不一致: 应为 -, 但却获得 CLOB


结论:



1. 创建视图时,不能同时有distinct和clob列

2. WMSYS.WM_CONCAT函数在不同的版本结果类型不一样,11.2.0.2和10.2.0.5之后都会返回CLOB


参考文章:

http://t.askmaclean.com/thread-3745-1-1.html

Problem with WMSYS.WM_CONCAT Function after Upgrading [ID 1300595.1]


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.

















 
  

你可能感兴趣的:(LOB,Oracle,PL/SQL开发,SQL)