简体   繁体   中英

Oracle | Replace a pattern in a blob

I have a blob column in a table with below content:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><UserPrefPropertyList xmlns="http://www.dummy.com/Platform" xmlns:AMS="http://www.dummy.com/AssetManagement">
    <UserPrefProperty PropertyType="PREFERRED_PM_SYMBOL">下�</UserPrefProperty>
    <UserPrefProperty PropertyType="PREFERRED_AM_SYMBOL">上�</UserPrefProperty>
    <UserPrefProperty PropertyType="PREFERRED_TIME_FORMAT">h:mm a z</UserPrefProperty>
    <UserPrefProperty PropertyType="PREFERRED_DATE_FORMAT">yyyy/M/d</UserPrefProperty>
</UserPrefPropertyList>

If you notice, there are special characters in below lines:

<UserPrefProperty PropertyType="PREFERRED_PM_SYMBOL">下�</UserPrefProperty>
<UserPrefProperty PropertyType="PREFERRED_AM_SYMBOL">上�</UserPrefProperty>

I want to update them from above to be like below:

<UserPrefProperty PropertyType="PREFERRED_PM_SYMBOL">PM</UserPrefProperty>
<UserPrefProperty PropertyType="PREFERRED_AM_SYMBOL">AM</UserPrefProperty>

Can someone please help me achieve this? Special characters can be any set of characters in input.

Let's call the table as USERS and column name as USER_CONFIG .

Thanks.

One solution is to use XMLTRANSFORM with an XSLT:

<?xml version="1.0"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:up="http://www.dummy.com/Platform" xmlns:AMS="http://www.dummy.com/AssetManagement">
      <xsl:template match="/up:UserPrefPropertyList">
        <UserPrefPropertyList>
        <xsl:for-each select="up:UserPrefProperty[@PropertyType='PREFERRED_PM_SYMBOL']">
            <UserPrefProperty PropertyType="PREFERRED_PM_SYMBOL">PM</UserPrefProperty>
        </xsl:for-each>
        <xsl:for-each select="up:UserPrefProperty[@PropertyType='PREFERRED_AM_SYMBOL']">
            <UserPrefProperty PropertyType="PREFERRED_AM_SYMBOL">AM</UserPrefProperty>
        </xsl:for-each>
        <xsl:for-each select="up:UserPrefProperty[@PropertyType!='PREFERRED_PM_SYMBOL'  and @PropertyType!='PREFERRED_AM_SYMBOL']">
            <UserPrefProperty PropertyType="PREFERRED_TIME_FORMAT"><xsl:value-of select="."/></UserPrefProperty>
        </xsl:for-each>
     </UserPrefPropertyList>
      </xsl:template>
    </xsl:stylesheet>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM