在MAterialized视图中使用ExtractValue和XMLType

时间:2011-07-21 15:45:40

标签: plsql oracle10g materialized-views xmltype

我正在尝试创建一个物化视图,该视图将显示表格中包含的XML数据的表格视图。我也希望使用自动刷新选项来确保MV始终是最新的。

一些背景: Oracle 10.2

表格def:

CREATE TABLE AGREEMENTEXTENSIONDATA (
    AGREEMENTEXTENSIONDATAID  NUMBER(18)          NOT NULL,
    EXTENSIONDATA             NCLOB,  
    AGREEMENTID               NUMBER(18)          NOT NULL)

extensiondata的例子:

<Extensions>
  <ExtensionData id="2" name="IncludePortfolio" type="4">true</ExtensionData>
</Extensions>

我在桌面上创建了一个日志:

CREATE MATERIALIZED VIEW LOG ON AGREEMENTEXTENSIONDATA
NOCACHE
LOGGING
NOPARALLEL
WITH PRIMARY KEY
INCLUDING NEW VALUES;

然后我尝试创建以下MV:

CREATE MATERIALIZED VIEW MV_ExtAgreements
REFRESH FAST ON COMMIT
ENABLE QUERY REWRITE
as
select AGREEMENTEXTENSIONDATAID,
       agreementid,
       extractvalue(xmltype(EXTENSIONDATA), '/Extensions/ExtensionData[@id=''1'']')
from agreementextensiondata
/

但是请收到以下消息:

ORA-30373: object data types are not supported in this context

我看到另一篇帖子建议使用函数从XML中提取值,但这也不起作用:

create or replace function extractVARCHAR2Extension(p_xml in clob, in_number in VARCHAR2) 
return varchar2 deterministic   
is 
begin  
   return xmltype(p_xml).extract('/Extensions/ExtensionData[@id=''' || in_number ||  ''']/text()').getstringval();
end;
/

但以下声明失败:

select extractVARCHAR2Extension(extensiondata,'2')
from agreementextensiondata 
    where agreementid = 136
ORA-00600: internal error code, arguments: [kghsccread1], [128], [0], [], [], [], [], []
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at "ALGOV5.EXTRACTVARCHAR2EXTENSION", line 5

...

欢迎任何指导,我可能在这里使用了错误的工具集。

感谢

1 个答案:

答案 0 :(得分:0)

p_xml in clob更改为p_xml in Nclob