I have column of XML type.There's a xml like this
<items>
<item type="xxx"><items>
<item type="xxx"><items>
</items>
I need to delete all type attributes. I know oracle has some functions for xml manipulation, but I don't get how to delete attributes.
How would such query look like ?
To delete rows that contain XML documents, use the DELETE SQL statement. Include a WHERE clause when you want to delete specific rows. You can specify which rows are to be deleted based on values within XML columns. To find values within XML documents, you need to use XQuery expressions.
You can optionally retrieve formal results of a SQL query as XML by specifying the FOR XML clause in the query. The FOR XML clause can be used in top-level queries and in subqueries. The top-level FOR XML clause can be used only in the SELECT statement.
The Delete command in SQL is a part of the Data Manipulation Language, a sub-language of SQL that allows modification of data in databases. This command is used to delete existing records from a table. Using this, you can either delete specific records based on a condition or all the records from a table.
Here is an example using the Oracle supplied SQL function deletexml
Acknowledgement to Jonas Lincoln as I am using his XPATH expression
SELECT deleteXML(xmltype.CREATEXML('<items>
<item type="xxx">a</item>
<item type="xxx">b</item>
</items>'),
'/items/item[@type="xxx"]/@type')
FROM dual
<items>
<item>a</item>
<item>b</item>
</items>
declare @xml as xml
set @xml = '
<items>
<item type="xxx">3</item>
<item type="xxx">4</item>
</items>'
SET @xml.modify('delete (/items/item[@type="xxx"]/@type)')
select cast(@xml as nvarchar(100))
<items>
<item>3</item>
<item>4</item>
</items>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With