i有一个名为"设备"的表,该表包含一个名为" xmldoc"的列的clob datatype。我想更新值字段。
name =" dropDirectory" value ="
/*Following is the sample XML:*/
<?xml version="1.0" encoding="UTF-8"?>
<Attributes>
<Attribute DataType="Text-40" DisplayName="PrinterAlias"
IsNotDeletable="Y" Modifiable="Y" Name="PrinterAlias" Value="QALABHP"/>
<Attribute DisplayName="PrintServerHostName"
Name="PrintServerHostName" Value="zzzzz"/>
<Attribute DisplayName="PrintServerPort" Name="PrintServerPort" Value="2723"/>
<Attribute DataType="Text-40" DisplayName="DropDirectory"
IsNotDeletable="Y" Modifiable="Y" **Name="DropDirectory" Value=""/>
</Attributes>
您可以如下更新它:
选择:
SELECT extract(xmltype(col1), '/Attributes/Attribute[@Name="DropDirectory"]/@Value')
FROM test_clob;
输出:
SQL> SELECT extract(xmltype(col1), '/Attributes/Attribute[@Name="DropDirectory"]/@Value')
FROM test_clob;
EXTRACT(XMLTYPE(COL1),'/ATTRIBUTES/ATTRIBUTE[@NAME="DROPDIRECTORY"]/@VALUE')
--------------------------------------------------------------------------------
更新:
UPDATE test_clob
SET col1 = UPDATEXML(xmltype(col1),
'/Attributes/Attribute[@Name="DropDirectory"]/@Value',to_char('google.com')).getClobVal()
输出:
SQL> /
EXTRACT(XMLTYPE(COL1),'/ATTRIBUTES/ATTRIBUTE[@NAME="DROPDIRECTORY"]/@VALUE')
--------------------------------------------------------------------------------
google.com
注意:用我的taberamame和columnname替换。
您没有指定您的Oracle版本。我假设是11克..(注意:如果您使用的是12c,则可能应该使用Xquery)。
在这里,我将值属性更新为new_value。
select xmlserialize(content updatexml(xmltype(
'<Attributes>
<Attribute DataType="Text-40" DisplayName="PrinterAlias"
IsNotDeletable="Y" Modifiable="Y" Name="PrinterAlias" Value="QALABHP"/>
<Attribute DisplayName="PrintServerHostName"
Name="PrintServerHostName" Value="zzzzz"/>
<Attribute DisplayName="PrintServerPort" Name="PrintServerPort" Value="2723"/>
<Attribute DataType="Text-40" DisplayName="DropDirectory"
IsNotDeletable="Y" Modifiable="Y" Name="DropDirectory" Value=""/>
</Attributes>'), '/Attributes/Attribute[@Name="DropDirectory"]/@Value', 'new_value'))
from dual
结果(clob):
<Attributes>
<Attribute DataType="Text-40" DisplayName="PrinterAlias" IsNotDeletable="Y" Modifiable="Y" Name="PrinterAlias" Value="QALABHP" />
<Attribute DisplayName="PrintServerHostName" Name="PrintServerHostName" Value="zzzzz" />
<Attribute DisplayName="PrintServerPort" Name="PrintServerPort" Value="2723" />
<Attribute DataType="Text-40" DisplayName="DropDirectory" IsNotDeletable="Y" Modifiable="Y" Name="DropDirectory" Value="new_value" />
</Attributes>