Replace xml in SQL - sql

I'm really new to SQL and I'm trying to replace a certain XML record with a brand new updated XML.
So i have a table that contains a list with records that all have a barcode ID, lets say barcode 123 has a column named XML that is filled with an XML A. I want to replace XML A with XML B that is saved on my hard drive.
Can anyone help me with this? It seems i can only find ways to directly replace data inside the xml itself, not replacing the entire XML.
I am using SQL server management studio 2012.
Thanks in advance.

Why not use an update query
update table_name set xml='all content of your xml file here' where BarcodeID=123;

Related

How do I replace partial xml text within a very long text string in an Oracle DB using SQL

I am very new to SQL and can't figure out this issue. I have tried searching Google but as you know, it returns so many results it would take for ever to find the answer, if it is even possible to do what I need.
I am using TOAD to try and update a very small portion of a very, very long xml statement in a data field within a table in an Oracle DB.
Small sample of xml text:
.....<DESCRIPTION>MXINPG-*RB4-CONGESTED-AT&T SC </DESCRIPTION> <OWNERUSERNAME>Existing Text</OWNERUSERNAME>....
I only need to replace the <OWNERUSERNAME> Existing Text </OWNERUSERNAME>
with
<OWNERUSERNAME>New Text </OWNERUSERNAME>
I tried a few SQL statements but none of them work. Any help is greatly appreciated.

Oracle 12c: Extract data (select) from XML (CLOB Type)

I need to extract some tag values from a XML code saved in a CLOB type column in Oracle 12c table.
Earlier we were using xmltype(COLUMN).extract('XPath/text()').getStringVal() to extract data from tags but its not working after our database upgrade to 12c.
We have XML Like:
<otm:ShipmentStatus
xmlns:gtm="http://xmlns.oracle.com/apps/gtm/transmission/v6.4"
xmlns:otm="http://xmlns.oracle.com/apps/otm/transmission/v6.4">
<otm:ServiceProviderAlias>
<otm:ServiceProviderAliasQualifierGid>
<otm:Gid>
<otm:Xid>GLOG</otm:Xid>
</otm:Gid>
</otm:ServiceProviderAliasQualifierGid>
<otm:ServiceProviderAliasValue>TEST.123</otm:ServiceProviderAliasValue>
</otm:ServiceProviderAlias>
<otm:IntSavedQuery>
<otm:IntSavedQueryGid>
<otm:Gid>
<otm:DomainName>TEST</otm:DomainName>
<otm:Xid>FIND_DELIVERY_NUMBER</otm:Xid>
</otm:Gid>......etc.
From this XML we have to select some values.
Please suggest some way to solve this problem. Feel free to ask if you need anything more.
Thank You.
Satyam
Example xml has namespaces. And you have to use it.
xmltype.extract('/otm:ShipmentStatus', 'xmlns:gtm="http://xmlns.oracle.com/apps/gtm/transmission/v6.4"
xmlns:otm="http://xmlns.oracle.com/apps/otm/transmission/v6.4"') extacting node from specify namespace
xmltype.extract('/*:ShipmentStatus') extractin node from any namespace

Concatenate char columns without using `for xml path` in SQL

I have got SQL Server 2005 and I want to get result like in the picture, I dont want to use for xml path method and make different way.
As #TT says in the comments "Concatenation with FOR XML PATH up until SQL Server 2016 is accepted as the best way to concatenate strings.", so you should use it.

SQL Server 2008 Query Result to XML FIle

I'm having some trouble dumping a query result into a XML file. I've read many articles about this subject but i still can't reach a decent solution for my case.
I have a procedure that outputs a query in XML format and it's working well:
alter proc pr_export_xml
as
declare #XmlOutput xml
set #XmlOutput = (select id,ref,sit from RepData for XML PATH('Produto'), ROOT('Produtos'), TYPE)
select #XmlOutput
go
What I need now is to get that result and dump into a file for later use. This procedure will be called during a trigger, so the dump into file must be done automatically.
I hope I was clear enough, any help will be appreciated.
Another alternative for this one is bcp utility.
Look into these.
http://www.brighthub.com/internet/web-development/articles/119542.aspx
Enable 'xp_cmdshell' SQL Server

how is xml stored in database

I have a table with one of the column being of type xml
I enetered record as insert into table_1 values(1,'')
i opened the mdf file in hex i found the "<>" missing.
This is how it looks.
00000000: 30000800 01000000 02000001 002b00df †0............+..
00000010: ff01b004 f0077000 72006f00 64007500 †......p.r.o.d.u.
00000020: 63007400 ef000001 f801f7 †††††††††††††c.t........
Can anybody help me with this?
Thanks!
mdf = SQL Server.
Which version? What is the field like?
XML field - well...
...it is stored in form of data (not documented), not as text. This is mosstly done to support the advanced query functionality. Not ethat this means storing XML and retrieving it may CHANGE THE STRING - as surplus spaces are removed. This eliminates... the validity of signed XML elements (if you use signatures in XML).
Basically, the XML structure is parsed and the data stored in a separate database structure.