Hi I have a blob of xml..
<string>1</string>
<string>2</string>
<string>3</string>
<string>4</string>
<string>11</string>
<string>1211</string>
<string>12331</string>
how would I get all the values using xpath/xquery in SQL
Thanks
The xpath //string will return all the values in the intire xml the xpath /string will return only the values in the root node.
And for using it in sql look at this post XPath to fetch SQL XML value
in oracle database
you have XMLType (see this) data type..
by this datatype you can get all the value..
all the examples are there itself, please go through that site.
Related
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
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.
I need to develop a sql server procedure which will convert table rows into xml and will transfer it to another stored procedure(Different server) through link server. On that server I have to take this xml data as input and again convert it into table rows. What will be the simplest and time efficient way to do this.
It is not possible to use the XML datatype as a parameter in stored procedure on a linked server. You have to use nvarchar(max) and convert to XML in the stored procedure.
To create the XML you should use FOR XML (SQL Server). RAW and AUTO is easy and if you need more control you could use PATH. I would stay away from EXPLICIT.
To shred the XML on the receiving side you should use nodes() Method (xml Data Type) and value() Method (xml Data Type).
Given that you are using SQL Server, you need only append FOR XML to your query.
I am using a XMLTYPE column in my table.
My schema is developed on this link on sqlfiddle
http://sqlfiddle.com/#!4/90306/1
I am able to fetch the value of building using the query there.
But my actual XML is
http://sqlfiddle.com/#!4/226cf
<m:Building>FBI</m:Building>
having a tag like <m:Building> .
But when i am trying to get the value of building here in second schema,i am getting error.
How i can achieve this ?
Thanks in advance.
You'll need to provide the XML Namespace to the extract function, for example:
SELECT
w.col1.extract
('/House/Building/text()', 'xmlns="rn://dt.com/batch/2010/08/13"').getStringVal()
"Building"
FROM tab1 w;
I've a XML string like that stored on my DB:
<?xml version="1.0" encoding="utf-8"?>
<AddressMaintenance>
<Label Name="lblAddress11">Address Line 1</Label><TextBox Name="txtAddress11">Zuellig Korea</TextBox>
</AddressMaintenance>
do you know if there is a way to extract the value Zuelling Korea using XMLQuery or SQL? I can't create a temporary table because it's a validate environment so I can only read that value. I know is possible using reg exp, but, if possible I try to use XML.
thanks,
Andrea
If this is stored in an XMLTYPE on a table you can use the Oracle XML functions to extract it using XPath:
SELECT
extractvalue(xmlcol, '/*/TextBox[#Name=''txtAddress11'']') txtaddress
FROM yourtable
Adapt the XPath to suit your needs.
See ExtractValue documentation or research other Oracle XML functions.
I should probably note that 11g and later, extractvalue is deprecated and you should use XMLQuery