Oracle XML Update故障

zzoitvuj  于 2023-03-29  发布在  Oracle
关注(0)|答案(2)|浏览(170)

我有一个BPMN2.0 XML值存储在一个表的CLOB中。
其具有与此类似结构

<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_17dxovu" targetNamespace="http://bpmn.io/schema/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.3">
  <bpmn:collaboration id="Collaboration_1wfeho3">
    <bpmn:participant id="Participant_0fn1t3b" name="Participant" processRef="Process_16me3ie" />
  </bpmn:collaboration>
  <bpmn:process id="Process_16me3ie">
    <bpmn:dataStoreReference id="DataStoreReference_16vk15q" name="Entity Data Repository" />
    <bpmn:startEvent id="Event_0ncce8e">
      <bpmn:outgoing>Flow_16gz7yv</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:task id="Activity_12og88i" name="oldval">
    </bpmn:task>

等等
我只想用一个新的名称更新任务的name属性。
所以我尝试了不同的口味

UPDATE process p
SET p.bpmn_xml = updatexml( p.bpmn_xml, '//bpmn:task[@id="Activity_12og88i" ]/name[text()="oldval"]/text()', 'newval' );

但我犯了很多错误

PL/SQL: ORA-00932: inconsistent datatypes: expected - got - at line xxx

指针赞赏。

vuktfyat

vuktfyat1#

你有四个问题:
1.根据this answer,您需要在UPDATEXML的第4个参数中包含名称空间;

  1. UPDATEXMLXMLTYPE作为第一个参数,因此您需要将CLOB转换为XMLTYPE;
    1.您希望使用XPathx 1 m4n1x;和
  2. XML无效,因为缺少结束标记。
    就像这样:
UPDATE process
SET bpmn_xml = updatexml(
                 XMLTYPE(bpmn_xml),
                 '//bpmn:task[@id="Activity_12og88i" and @name="oldval"]/@name',
                 'newval',
                 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
                  xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
                  xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
                  xmlns:di="http://www.omg.org/spec/DD/20100524/DI"'
               ).getClobVal();

其中,对于示例数据:

CREATE TABLE process (bpmn_xml CLOB );

INSERT INTO process (bpmn_xml)
VALUES ('<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_17dxovu" targetNamespace="http://bpmn.io/schema/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.3">
  <bpmn:collaboration id="Collaboration_1wfeho3">
    <bpmn:participant id="Participant_0fn1t3b" name="Participant" processRef="Process_16me3ie" />
  </bpmn:collaboration>
  <bpmn:process id="Process_16me3ie">
    <bpmn:dataStoreReference id="DataStoreReference_16vk15q" name="Entity Data Repository" />
    <bpmn:startEvent id="Event_0ncce8e">
      <bpmn:outgoing>Flow_16gz7yv</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:task id="Activity_12og88i" name="oldval">
    </bpmn:task>   
  </bpmn:process>
</bpmn:definitions>');

将XML更新为:
| XML文档|
| --------------|
| <bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_17dxovu" targetNamespace="http://bpmn.io/schema/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.3"><bpmn:collaboration id="Collaboration_1wfeho3"><bpmn:participant id="Participant_0fn1t3b" name="Participant" processRef="Process_16me3ie"/></bpmn:collaboration><bpmn:process id="Process_16me3ie"><bpmn:dataStoreReference id="DataStoreReference_16vk15q" name="Entity Data Repository"/><bpmn:startEvent id="Event_0ncce8e">bpmn:outgoing流量_16gz7yv</bpmn:outgoing></bpmn:startEvent><bpmn:task id="Activity_12og88i" name="newval"> </bpmn:task></bpmn:process></bpmn:definitions> |
fiddle

4ioopgfo

4ioopgfo2#

您收到的错误消息表明输入和输出值的数据类型不一致,这可能是由于对updatexml()函数使用了不正确的参数或语法造成的。
要更新BPMN2.0 XML值中任务元素的name属性,可以使用以下SQL语句:

UPDATE process p
SET p.bpmn_xml = updatexml(
  p.bpmn_xml,
  '//bpmn:task[@id="Activity_12og88i"]/@name',
  'newval'
)
WHERE existsNode(p.bpmn_xml, '//bpmn:task[@id="Activity_12og88i"]/@name') = 1;

此SQL语句使用updatexml()函数将id属性等于"Activity_12og88i"bpmn:taskName元素更新为新值'newval'where子句确保在更新name属性之前,任务元素存在于BPMN2.0 XML值中。

相关问题