Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

sql - How to update XML attribute in clob Oracle using XMLQuery

Oracle table name: SR_DATA;

Table field name: XMLDATA type CLOB;

Field value:

<module xmlns="http://www.mytest.com/2008/FMSchema">
<tmEsObjective modelCodeScheme="A" modelCodeSchemeVersion="01" modelCodeValue="ES_A"></tmEsObjective>
</module>

I need to update the value of the attribute "modelCodeValue" into ES_B.

This is the code:

UPDATE SR_DATA
  SET XMLDATA =
    XMLQuery('copy $i := $p1 modify
                ((for $j in $i/module/tmEsObjective/@modelCodeValue
                  return replace value of node $j with $p2))  
                )
                return $i'
             PASSING XMLType(REPLACE(xmldata, 'xmlns="http://www.mytest.com/2008/FMSchema"', '')) AS "p1",
                     'ES_B' AS "p2"
             RETURNING CONTENT);

This code returns the error code: ORA-00932: inconsistent datatypes: expected CLOB got -

question from:https://stackoverflow.com/questions/65886704/how-to-update-xml-attribute-in-clob-oracle-using-xmlquery

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use getclobval() like this:

UPDATE SR_DATA
  SET XMLDATA = 
     XMLTYPE.GETCLOBVAL(XMLQuery('copy $i := $p1 modify
                            ((for $j in $i/module/tmEsObjective/@modelCodeValue
                              return replace value of node $j with $p2))  
                            
                            return $i'
                         PASSING XMLType(REPLACE(xmldata, 'xmlns="http://www.mytest.com/2008/FMSchema"', '')) AS "p1",
                                 'ES_B' AS "p2"
                         RETURNING CONTENT ));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...