Oracle:如何创建一个快速刷新的物化视图,从XMLType中提取数据?
我有一个包含两列的表 xml_documents
:一个 document_id
列(主键)和一个包含一些 XML 数据的 xml
列,这是一个架构-less XMLType
。我可以仅使用 document_id
创建一个物化视图:
create materialized view mv refresh fast on commit as
select document_id
from xml_documents
这工作正常,但不是很有用。正如您所期望的,我希望物化视图从 XML 中提取数据,为此我使用 extractValue()
。我正在尝试以下操作:
create materialized view mv refresh fast on commit as
select document_id, extractValue(xml, '/my/gaga') gaga
from xml_documents
失败并显示:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
我应该如何在提交物化视图上创建快速刷新以从 XML 中提取值?
I have a table xml_documents
with two columns: a document_id
column (primary key) and an xml
column with some XML data, which is a schema-less XMLType
. I can create a materialized view with just the document_id
with:
create materialized view mv refresh fast on commit as
select document_id
from xml_documents
This works fine, but isn't very useful. As you might expect, I'd like the materialized view to extract data from the XML, and for this I use extractValue()
. I am trying the following:
create materialized view mv refresh fast on commit as
select document_id, extractValue(xml, '/my/gaga') gaga
from xml_documents
This fails with:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
How should I go about to create a fast refresh on commit materialized view that extract values from XML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 XMLType(可能)存储为 CLOB。使用如下查询查找隐藏列:
然后创建一个函数将 CLOB 转换为 XMLType,并提取值。请注意,“确定性”关键字是必要的,尽管
我不知道为什么。在 SQL 和 PL/SQL 之间来回传递数据会很慢,但如果您使用物化视图,事情可能会很慢
已经很慢了。
然后删除并创建物化视图,并将系统列传递到函数中:
我不确定是否使用系统生成的隐藏列。它有效,但似乎不是一个真正的好主意。至少它会成功
在不同的系统上创建对象很困难 - 您每次都需要找到新的列名称。
当 LOB 工作正常时 XMLType 却不起作用,这似乎很奇怪。我找不到任何关于此的文档;我不确定这是否是一个错误,一个未实现的功能,或者是否有一些神奇的设置可以让它工作。如果没有其他人可以提供更好的答案,那么在使用上述方法之前可能需要先咨询 Oracle 支持人员。
Your XMLType is (probably) stored as a CLOB. Find the hidden column with a query like this:
Then create a function to convert a CLOB into an XMLType, and extract the value. Note that the "deterministic" keyword is necessary, although
I'm not sure why. Passing data back and forth between SQL and PL/SQL will be slow, but if you're using a materialized view things are probably
already slow.
Then drop and create your materialized view with the system column passed into the function:
I'm unsure about using a system-generated hidden column. It works, but doesn't seem like a really good idea. At the very least it will make it
difficult to create the object on different systems - you'll need to find the new column name each time.
It seems weird that XMLTypes don't work when LOBs work fine. I can't find any documentation about this; I'm not sure if it's a bug, an unimplemented feature, or if there's some magic setting that will make it work. If no one else can provide a better answer, it might be worth checking with Oracle support before you use the above approach.