Query regarding FOR XML PATH
I have found a script that contains the following:
stuff(
select
', ' +
fielda
from
tablea
for
xml path (''),
type).value
'nvarchar(max)')
,1,2,
anotherfield
This will concatenate field a and the stuff will remove the leading comma.
I have amended the script to the following and it still works:
Stuff(
select
', ' +
fielda
from
tablea
for
xml path (''))
,1,2,
Afield,
Please could somebody tell me why the following has been inserted after the
for xml path ('')
section
type).value
('.', 'nvarchar(max)')
Erland - I just did a quick test. The differences weren't as bad as the subtree estimates would have indicated but they weren't exactly close either. The typed version (on average) took just over twice as long to execute.
Test conditions were as follows:
AdventureWorks2012 database
On average, the non-typed version executed in ~190 ms and the typed version executes in ~405 ms.
Test bed was the following:
@@VERSION =
Microsoft SQL Server 2012 - 11.0.2218.0 (X64)
Jun 12 2012 13:05:25
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
Hardware =
Processor: Core i7-4770K @ 3.50GHz (4 physical cores / 8 logical cores)
Ram: 16.0 GB @ 2400 MHz
HD: SSD
Here are the two test scripts that I used... (each run in it own SSMS tab)
-- Typed version --
DECLARE @BegDT DATETIME2(7) = SYSDATETIME()
SELECT
sod1.SalesOrderID,
STUFF((
SELECT ', ' + CAST(sod2.ProductID AS VARCHAR(8))
FROM Sales.SalesOrderDetail sod2
WHERE sod1.SalesOrderID = sod2.SalesOrderID
FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 2, '') AS csv
FROM
Sales.SalesOrderDetail sod1
GROUP BY
sod1.SalesOrderID
SELECT DATEDIFF(ms, @BegDT, SYSDATETIME()) AS ExecTimeMS
-- Non-typed version --
DECLARE @BegDT DATETIME2(7) = SYSDATETIME()
SELECT
sod1.SalesOrderID,
STUFF((
SELECT ', ' + CAST(sod2.ProductID AS VARCHAR(8))
FROM Sales.SalesOrderDetail sod2
WHERE sod1.SalesOrderID = sod2.SalesOrderID
FOR XML PATH('')), 1, 2, '') AS csv
FROM
Sales.SalesOrderDetail sod1
GROUP BY
sod1.SalesOrderID
SELECT DATEDIFF(ms, @BegDT, SYSDATETIME()) AS ExecTimeMS
If you see holes in my test approach, please let me know.
Thanks,
Jason
Jason Long
Similar Messages
-
Execute SQL Task - FOR XML PATH query error
I have the following query
SELECT pl.Id,
pl.StartTime,
pl.EndTime,
pl.PackageName,
pl.Computer,
pl.Operator,
CASE WHEN (CHARINDEX('stack trace', pl.ErrorDescription) > 0) Then
SUBSTRING(pl.ErrorDescription, 0, CHARINDEX('stack trace', pl.ErrorDescription))
ELSE
pl.ErrorDescription
END as ErrorDescription
ISNULL(ErrorFile,'') as ErrorFile,
'Not Applicable' as SourceSystem
FROM etl.PackageLog as pl
WHERE pl.Processed = 0
ORDER BY pl.StartTime, pl.PackageName
FOR XML PATH('Row'), ROOT(N'FieldingCounts')
in a Execute SQL Task and i get the following error:
[Execute SQL Task] Error: Executing the query "SELECT pl.Id,
pl.StartTime,
pl.EndTime,
pl.Package..." failed with the following error: "An invalid character was found in text content.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
The query execute without problem in database and in the ssis package doens't run because of the column
CASE WHEN (CHARINDEX('stack trace', pl.ErrorDescription) > 0) Then
SUBSTRING(pl.ErrorDescription, 0, CHARINDEX('stack trace', pl.ErrorDescription))
ELSE
pl.ErrorDescription
END as ErrorDescription
Any help to overcome the problem?
ThanksHi,
It looks like that you must be trying to set the result of the query to some variable from the Execute SQL Task. If yes, make sure that the target variable is of the correct data type where XML string can fit into. Considering that in SSIS, we have
some limit for XML strings.
Please let me know if it doesn't help.
Thanks,
Nimit -
Biztalk WCF-SQL polling sample using a FOR XML Path
I've been searching in the web for a sample that uses FOR XML "PATH" to poll the SQL database . The result returned from my query is a parent child data and FOR XML PATH is the best choice to structure it in that way . I guess I'm missing something while
generating the schemas from this stored procedure.
I guess Dan Rosanova has touched on this concept (http://social.technet.microsoft.com/wiki/contents/articles/3480.aspx)
, but its using XML Auto. Again there is no sample available so makes things a bit difficult.
Can someone point to a sample walkthrough , generating the schemas and then later using it in the application.
Thanks
AnthstoneI used XMLPolling and it worked for me. you can go for XMLPolling. Steps to be followed:
1) Create the SP which will have the SELECT query similar to below:
;WITH XMLNAMESPACES (default 'http://yourcustomnamespace')
Select * from Employee FOR XML PATH('YourCustomRootNode')
2) Create a schema out of the table using the following query
Select * from Employee for
xml
auto,
xmlschema
3) Re-name the root name and namespace as per you mentioned in point#1 (YourCustomRootNode)
4) Create an Envelope Schema and refer the schema from point#3. Also make a note of the root node name and namespace that we need to specify
in the admin console.
5) Assign the Body XPath to debatch. Refer
this. Deploy the solution.
6) In the Admin console, add the Root Node Name and namespace mentioned in point#4 under "XmlStoredProcedureRoodNodeName" and "XmlStoredProcedureRoodNodeNamespace"
There you go. I did this for debatching. You can do for nomarl batch message instead of Envelope create a normal document schema.
Thanks
SKGuru -
Hi all,
I am learning XPATH and XQUERY from the Book "Pro T-SQL 2008 Programmer's Guide" written by Michael Coles, (published by apress). I copied the Code Listing 12-8 FOR XML PATH Using XPath Node Tests (listed below) and executed it in my
SQL Server 2012 Management Studio:
--Coles12_8.sql // saved in C:/Documemnts/SQL Server Management Studio
-- Coles Listing 12-8 FOR XML PATH Using XPATH Node Tests
-- Retrieving Name and E-mail Addresses with FOR XML PATH in AdvantureWorks
-- 16 March 2015 0935 AM
USE AdventureWorks;
GO
SELECT
p.NameStyle AS "processing-instruction(nameStyle)",
p.BusinessEntityID AS "Person/@ID",
p.ModifiedDate AS "comment()",
pp.PhoneNumber AS "test()",
FirstName AS "Person/Name/First",
MiddleName AS "Person/Name/Middle",
LastName AS "Person/Name/Last",
EmailAddress AS "Person/Email"
FROM Person.Person p
INNER JOIN Person.EmailAddress e
ON p.BusinessEntityID = e.BusinessEntityID
INNER JOIN Person.PersonPhone pp
ON p.BusinessEntityID = pp.BusinessEntityID
FOR XML PATH;
I got the following error message:
Msg 6850, Level 16, State 1, Line 2
Column name 'test()' contains an invalid XML identifier as required by FOR XML; '('(0x0028) is the first character at fault.
I have no ideas why I got this error message. Please kindly help and advise me how to resolve this error.
Thanks in advance, Scott ChangHi Michelle, Thanks for your nice response.
I corrected the mistake and executed the revised code. It worked nicely.
I just have one question to ask you about the appearance of the xml output of my Co;les12_8.sql:
<row>
<?nameStyle 0?>
<Person ID="1" />
<!--2003-02-08T00:00:00-->697-555-0142<Person><Name><First>Ken</First><Middle>J</Middle><Last>Sánchez</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="2" />
<!--2002-02-24T00:00:00-->819-555-0175<Person><Name><First>Terri</First><Middle>Lee</Middle><Last>Duffy</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="3" />
<!--2001-12-05T00:00:00-->212-555-0187<Person><Name><First>Roberto</First><Last>Tamburello</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="4" />
<!--2001-12-29T00:00:00-->612-555-0100<Person><Name><First>Rob</First><Last>Walters</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="5" />
<!--2002-01-30T00:00:00-->849-555-0139<Person><Name><First>Gail</First><Middle>A</Middle><Last>Erickson</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="6" />
<!--2002-02-17T00:00:00-->122-555-0189<Person><Name><First>Jossef</First><Middle>H</Middle><Last>Goldberg</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="7" />
<!--2003-03-05T00:00:00-->181-555-0156<Person><Name><First>Dylan</First><Middle>A</Middle><Last>Miller</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="8" />
<!--2003-01-23T00:00:00-->815-555-0138<Person><Name><First>Diane</First><Middle>L</Middle><Last>Margheim</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="9" />
<!--2003-02-10T00:00:00-->185-555-0186<Person><Name><First>Gigi</First><Middle>N</Middle><Last>Matthew</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="10" />
<!--2003-05-28T00:00:00-->330-555-2568<Person><Name><First>Michael</First><Last>Raheem</Last></Name><Email>[email protected]</Email></Person></row>
<row>
<?nameStyle 0?>
<Person ID="11" />
<!--2004-12-29T00:00:00-->719-555-0181<Person><Name><First>Ovidiu</First><Middle>V</Middle><Last>Cracium</Last></Name><Email>[email protected]</Email></Person></row>
<row>
I feel this xml output is not like the regular xml output. Do you know why it is diffrent from the regular xml xml output? Please comment on this matter.
Thanks,
Scott Chang
What do you mean by regular xml document? Are you referring to fact that its missing a root element? if yes it can be added as below
USE AdventureWorks;
GO
SELECT
p.NameStyle AS "processing-instruction(nameStyle)",
p.BusinessEntityID AS "Person/@ID",
p.ModifiedDate AS "comment()",
pp.PhoneNumber AS "text()",
FirstName AS "Person/Name/First",
MiddleName AS "Person/Name/Middle",
LastName AS "Person/Name/Last",
EmailAddress AS "Person/Email"
FROM Person.Person p
INNER JOIN Person.EmailAddress e
ON p.BusinessEntityID = e.BusinessEntityID
INNER JOIN Person.PersonPhone pp
ON p.BusinessEntityID = pp.BusinessEntityID
FOR XML PATH('ElementName'),ROOT('RootName');
replace ElementName and RootName with whatever name you need to set for element as well as the root element
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
"for XML path " Oracle equivalent of this SQL expression
SELECT TheID,
REPLACE(
RTRIM(
SELECT StudentID + ' '
FROM StudentinSchoolLocation TL
WHERE (LocationID = Results.LocationID)
FOR XML PATH ('')
) AS StudentIDs,
What is the equivalent of 'For XML path' used above
The goal is to get a concatenated list of the group by columns. Like where ever the location is same , get the studentIds and make a comma seperated list of all ids for common location
Works perfectly in SQL.
Thank youHi,
user6287828 wrote:
The goal is to get a concatenated list of the group by columns. Like where ever the location is same , get the studentIds and make a comma seperated list of all ids for common locationThat's called "String Aggregation"
[AskTom.oracle.com|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402] shows several different ways to do it.
I recommend the first one, the user-defined function STRAGG, which you can copy from that page.
On Oracle 10 (and up) you may have a similar function, WM_CONCAT (owned by WMSYS), already installed.
WM_CONCAT is not documented, so you may not want to use it in your Production applications.
STRAGG is not so convenient if the order of items in the concatenated string is important.
In that case, use XMLAGG or SYS_CONNECT_BY_PATH, as shown later in the asktom page.
MODEL can also do ordered string aggregation. -
Use of variables in "FOR XML PATH"
Other than using dynamic sql (which we don't want to use) is there a way to use a variable in For XML Path, e.g.
select
FOR XML PATH (@BookName), ROOT('Book'), TYPE
TIA,
edm2In terms of general XML design this is poor. An element is normally a 'thing', and the attributes are normally the properties of that thing. Therefore in your case you would have a Book property with a 'name' attribute. It would be impossible
to create an XSD for your xml, and makes it awkward for readers of your xml - how do they know the book name beforehand? Creating this xml in the normal fashion would also make it easy to create without any messing around ( string manipulation,
other hacks ), eg
DECLARE @BookName NVARCHAR(20) = 'SomeBook'
SELECT
@BookName "@name"
-- Other book attributes
FOR XML PATH ('Book'), ROOT('Books'), TYPE
So now you have a Book item(s) within a Books collection. Easy! : ) -
Generate xml using FOR XML PATH from table with hierarchy
I need to create xml from a table like:
EL1 EL2 EL3 Attr01 Attr02 Attr03 Attr04
E10, , ,a,b,c,d
E10,E1010, ,a,b,c,d
E10,E1010,E101010,a,b,c,d
E10,E1010,E101020,a,b,c,d
E10,E1010,E101030,a,b,c,d
E10,E1020, ,a,b,c,d
E10,E1020,E102010,a,b,c,d
E20, , ,a,b,c,d
E20,E2010, ,a,b,c,d
E20,E2010,E201010,a,b,c,d
E20,E2020, ,a,b,c,d
E20,E2020,E202010,a,b,c,d
E20,E2020,E202020,a,b,c,d
The hierarchy is EL1--EL2--EL3, and the 3 columns should be elements of xml;
The other for columns Attr01,Attr02,Attr03,Attr04 should be attributes of xml;
The actual table could have more than 500 rows(there are many values for El1,EL2,and EL3).
The expected xml should like:
<root>
<E10 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E1010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E101010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E101020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E101030 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E1010>
<E1020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E102010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E1020>
</E10>
<E20 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E2010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E201010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E2010>
<E2020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E202010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E202020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E2020>
</E20>
</root>
I create a sample Src table:
CREATE TABLE Src
EL1 VARCHAR(10),
EL2 VARCHAR(10),
EL3 VARCHAR(10),
Attr01 VARCHAR(10),
Attr02 VARCHAR(10),
Attr03 VARCHAR(10),
Attr04 VARCHAR(10)
GO
INSERT INTO Src
(EL1,EL2,EL3,Attr01,Attr02,Attr03,Attr04
SELECT 'E10','','','a','b','c','d'
UNION SELECT 'E10','E1010','','a','b','c','d'
UNION SELECT 'E10','E1010','E101010','a','b','c','d'
UNION SELECT 'E10','E1010','E101020','a','b','c','d'
UNION SELECT 'E10','E1010','E101030','a','b','c','d'
UNION SELECT 'E10','E1020','','a','b','c','d'
UNION SELECT 'E10','E1020','E102010','a','b','c','d'
UNION SELECT 'E20','','','a','b','c','d'
UNION SELECT 'E20','E2010','','a','b','c','d'
UNION SELECT 'E20','E2010','E201010','a','b','c','d'
UNION SELECT 'E20','E2020','','a','b','c','d'
UNION SELECT 'E20','E2020','E202010','a','b','c','d'
UNION SELECT 'E20','E2020','E202020','a','b','c','d'
GO
I tried to use FOR XML PATH to generate xml for the sample data. When the records increase to a few hundreds, it's not a good idea.
Here is my script:
SELECT
(SELECT Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101010'
FOR XML PATH('E101010'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101020'
FOR XML PATH('E101020'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101030'
FOR XML PATH('E101030'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E1010' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E1010'),TYPE
) AS 'node()'--1010
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E102010'
FOR XML PATH('E102010'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E1020' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E1020'),TYPE
) AS 'node()'--1020
FROM Src
WHERE EL1 = 'E10' AND (EL2 ='' AND EL3 ='')
FOR XML PATH('E10'),TYPE) 'node()'
,(SELECT Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E201010'
FOR XML PATH('E201010'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E2010' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E2010'),TYPE
) AS 'node()'--2010
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E202010'
FOR XML PATH('E202010'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E202020'
FOR XML PATH('E202020'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E2020' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E2020'),TYPE
FROM Src
WHERE EL1 = 'E20' AND (EL2 ='' AND EL3 ='')
FOR XML PATH('E20'),TYPE) AS 'node()'
FOR XML PATH(''),ROOT('root')
If I get a few hundreds of rows, how huge the script should be. Does anyone have better solution for this? Thanks.
TaowBob,
Thanks! And sorry for late feedback.
The XSD requires the xml structures like the following
<Schools>
<School01>Some school</School01>
<School02>Some other school</School02>
</Schools>
I have to use the number in the element name.
Right now I just use the nested FOR XML PATH, although I have to write thousand lines code.
Thanks anyway.
Tao
Tao -
Does oracle have similar functionality like MsSql "for xml path('')"
Does oracle have similar build in functionality like MsSql “for xml path(‘’)” , or in another word, it can enforce the result set(multiple rows) into ONE line such kind of presentation way.
Thanks in advance. Any help would be greatly appreciated.Here I would like specify my question mnore clearly,
CREATE TABLE t(
line NUMBER(3),
site VARCHAR2(4),
phase VARCHAR2(5),
test VARCHAR2(25));
INSERT INTO t VALUES (1, '0100', '*','1111111111111111111111111' );
INSERT INTO t VALUES (2, '0100', '=','2222222222222222222222222' );
INSERT INTO t VALUES (3, '0100', '=','3333333333333333333333333' );
INSERT INTO t VALUES (4, '0100', '*','4444444444444444444444444' );
INSERT INTO t VALUES (5, '0100', '=','5555555555555555555555555' );
INSERT INTO t VALUES (6, '0200', '*','6666666666666666666666666' );
Here I want to retrieve the 'line' column information in ONE line way
select line from t I want the result is like '1,2,3,4,5,6'
Any generous help would be greatly appreciated!!! -
Query language for XML documents
Which is a better (efficiency in terms of memory management) query language for interacting with XML documents.The query language shouls support 'insert', 'delete', 'update' and 'select' commands. How fast is database as compared to XML ( database being replaced by XML) when only 'insert' n 'select' commands are issued?
Hi,
I suggest you use the Sunopsis JDBC for XML driver that will let you perform all kind of SQL statements on your XML files. It is a type 4 driver so it's very use to use. You may have more information and download it here:
http://www.sunopsis.com/corporate/us/products/jdbcforxml/
Hope that will help
Simo Fernandez -
Query language for XML that is going to remove use of database
Friends,
I want to know whether my idea is feasible or not.
I want to make a query language similar to SQL for XML which is going to remove the need for database for a large extent.
Their will be queries for making table,extracting data,making foreign key all through XML and no database.
I just want to know that is their any market value for such a project and will it be sellable,so that i can start working on it.There is no way to judge any future market for such a thing.
As it is, XML is widely abused, having mutated from its original purpose, a markup language readable by both machine and human, to a general data interchange language. It winds up being extremely slow and convoluted, in some cases overwhelming the hardware when a simple and common error occurs, then having to catch up. A big part of this is the silly and redundant method of defining metadata, again and again and again and again.
So what you want to do is create a database which will be highly formatted with redundant information, dynamically. This is silly, why does data need to be stored in a human readable format? It doesn't always even need to be presented in a human readable format! Why the heck would you need to read the bits of an mp4? Steganography?
What you are proposing is the exact opposite of what is needed. What is needed is a way to describe metadata for many different kinds of data, in a manner that can be interpreted by both man and machine at appropriate times, extensible for various paradigms.
What can be sold, on the other hand, is another question entirely, and not technical at all.
First definition of database that pops up during a search: an organized body of related information
Why would you want to get rid of that? -
Query required for xml processing.
This data is present in clob i need to extract the below mentioned field.
expected query is
select
extractvalue( xmltype(table1.column1), '/UserProfileSnapshot/UserInfo/Attribute[@name="Users.Display Name"]' )
from table1
first line is incorrect <?xml version = '1.0' encoding = 'UTF-8'?>
Can anyone please help me in making a query for this incorrect clob data.
As we cannot change this first line in data.
"<?xml version = '1.0' encoding = 'UTF-8'?>
<UserProfileSnapshot key="224" version="1.0">
<UserInfo>
<Attribute name="Users.Display Name">testfuturedate102, Mr. user</Attribute>
<Attribute name="USR_UDF_HR_ORG_ID">202</Attribute>
<Attribute name="Users.Xellerate Type">End-User</Attribute>
<Attribute name="Users.Role">Employee</Attribute>
<Attribute name="Users.First Name">user</Attribute>
<Attribute name="Users.Status">Active</Attribute>
<Attribute name="USR_UDF_LOCATION_ID">1737</Attribute>
<Attribute name="Users.Provisioned Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Title">MR.</Attribute>
<Attribute name="USR_UDF_LOCATION_CODE">HR- New York</Attribute>
<Attribute name="Country">US</Attribute>
<Attribute name="State">NY</Attribute>
<Attribute name="Users.Password Reset Attempts Counter">0</Attribute>
<Attribute name="Users.Disable User">0</Attribute>
<Attribute name="Users.Change Password At Next Logon">1</Attribute>
<Attribute name="USR_CN_GENERATED">0</Attribute>
<Attribute name="USR_UDF_EFFECTIVE_START_DATE">2013-03-08 00:00:00 -0500</Attribute>
<Attribute name="Postal Code">10001</Attribute>
<Attribute name="Users.Update Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Employee Number">2335</Attribute>
<Attribute name="USR_UDF_DEPARTMENT_NAME">Vision Corporation</Attribute>
<Attribute name="Users.Last Name">testfuturedate102</Attribute>
<Attribute name="Users.End Date">4712-12-31 00:00:00 -0500</Attribute>
<Attribute name="Hire Date">2013-02-28 00:00:00 -0500</Attribute>
<Attribute name="USR_UDF_PERSON_ID">31967</Attribute>
<Attribute name="USR_UDF_IS_MANAGER">N</Attribute>
<Attribute name="Users.Creation Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Street">500 Madison Ave</Attribute>
<Attribute name="Users.User ID">31967</Attribute>
<Attribute name="USR_UDF_CITY">New York</Attribute>
<Attribute name="Users.Lock User">0</Attribute>
<Attribute name="Users.Updated By Login" key="4">OIMINTERNAL</Attribute>
<Attribute name="Users.Created By Login" key="4">OIMINTERNAL</Attribute>
<Attribute name="Users.Login Attempts Counter">0</Attribute>
<Attribute name="Organizations.Organization Name" key="4">Integra</Attribute>
</UserInfo>
</UserProfileSnapshot>"As said in {thread:id=2545133}, the quotes are certainly not the issue.
This works fine for me on 11.2.0.2 :
SQL> insert into table1 (column1)
2 values (
3 '<?xml version = ''1.0'' encoding = ''UTF-8''?>
4 <UserProfileSnapshot key="224" version="1.0">
5 <UserInfo>
6 <Attribute name="Users.Display Name">testfuturedate102, Mr. user</Attribute>
7 <Attribute name="USR_UDF_HR_ORG_ID">202</Attribute>
8 <Attribute name="Users.Xellerate Type">End-User</Attribute>
9 <Attribute name="Users.Role">Employee</Attribute>
10 <Attribute name="Users.First Name">user</Attribute>
11 <Attribute name="Users.Status">Active</Attribute>
12 <Attribute name="USR_UDF_LOCATION_ID">1737</Attribute>
13 <Attribute name="Users.Provisioned Date">2013-04-23 10:04:48 -0400</Attribute>
14 <Attribute name="Title">MR.</Attribute>
15 <Attribute name="USR_UDF_LOCATION_CODE">HR- New York</Attribute>
16 <Attribute name="Country">US</Attribute>
17 <Attribute name="State">NY</Attribute>
18 <Attribute name="Users.Password Reset Attempts Counter">0</Attribute>
19 <Attribute name="Users.Disable User">0</Attribute>
20 <Attribute name="Users.Change Password At Next Logon">1</Attribute>
21 <Attribute name="USR_CN_GENERATED">0</Attribute>
22 <Attribute name="USR_UDF_EFFECTIVE_START_DATE">2013-03-08 00:00:00 -0500</Attribute>
23 <Attribute name="Postal Code">10001</Attribute>
24 <Attribute name="Users.Update Date">2013-04-23 10:04:48 -0400</Attribute>
25 <Attribute name="Employee Number">2335</Attribute>
26 <Attribute name="USR_UDF_DEPARTMENT_NAME">Vision Corporation</Attribute>
27 <Attribute name="Users.Last Name">testfuturedate102</Attribute>
28 <Attribute name="Users.End Date">4712-12-31 00:00:00 -0500</Attribute>
29 <Attribute name="Hire Date">2013-02-28 00:00:00 -0500</Attribute>
30 <Attribute name="USR_UDF_PERSON_ID">31967</Attribute>
31 <Attribute name="USR_UDF_IS_MANAGER">N</Attribute>
32 <Attribute name="Users.Creation Date">2013-04-23 10:04:48 -0400</Attribute>
33 <Attribute name="Street">500 Madison Ave</Attribute>
34 <Attribute name="Users.User ID">31967</Attribute>
35 <Attribute name="USR_UDF_CITY">New York</Attribute>
36 <Attribute name="Users.Lock User">0</Attribute>
37 <Attribute name="Users.Updated By Login" key="4">OIMINTERNAL</Attribute>
38 <Attribute name="Users.Created By Login" key="4">OIMINTERNAL</Attribute>
39 <Attribute name="Users.Login Attempts Counter">0</Attribute>
40 <Attribute name="Organizations.Organization Name" key="4">Integra</Attribute>
41 </UserInfo>
42 </UserProfileSnapshot>'
43 );
1 row inserted
SQL>
SQL> select x.*
2 from table1 t
3 , xmltable(
4 '/UserProfileSnapshot/UserInfo'
5 passing xmltype(t.column1)
6 columns userdisplay_name varchar2(30) path 'Attribute[@name="Users.Display Name"]'
7 , user_role varchar2(30) path 'Attribute[@name="Users.Role"]'
8 ) x ;
USERDISPLAY_NAME USER_ROLE
testfuturedate102, Mr. user Employee -
Query regarding sending XML over HTTP Post request
Hello,
I am trying to send XML data from a server to client via HTTP Post request
And vice versa � receive the data by a client
Assume that the xml data looks something like
<?xml+version="1.0"?>
So my post query will look like
http://<IP Address>:<port>/
POST /MessageReceiver.jsp HTTP/1.0
Host: www.SomeHost.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 38
%3C%3Fxml%2Bversion%3D%221.0%22%3F%3E+
This information will be received by the client and converted back to xml data.
My query is - is there some library/open-source stuff that
does the process of transcoding the entity's non-ASCII characters
at the server side
and decoding the URL back to human-readable form at the client side?
i.e. I need a simple mechanism to convert
<?xml+version="1.0"?>
to
%3C%3Fxml%2Bversion%3D%221.0%22%3F%3E+
at the server side, while sending data
and do the opposite at the client side to get the xml back.
Also could some one confirm if JTidy is a right tool to check if the xml is well-formed?
Or is there any other standard tool that checks for well-formed properties of xml?
regards,
Deepak.java.net.URLEncoder / URLDecoder?
Also could some one confirm if JTidy is a right tool to check if the xml is well-formed?No, it's for parsing HTML. An XML parser is checking for well-formedness in any case. -
Query regarding composite.xml and bpel
Hi,
I am absolutely new to SOA.Last day, I was experimenting with BPEL processes.I dragged a BPEL process(TestBPEL) onto the SOA composite and exposed it as a SOAP service.Now the component(testbpel_client_ep) that is being shown in the left swimlane wired to the BPEL process, what is that?I mean is that a service itself.Again in the .componentType file, I saw a service was defined but the name of the service defined was testbpel_client.But I didn't define any other service,so where did that service come from?Again in the composite source I saw the follwing code was generated:-
<service name="testbpel_client_ep" ui:wsdlLocation="TestBPEL.wsdl">
<interface.wsdl interface="http://xmlns.oracle.com/PatientDataService_jws/Test/TestBPEL#wsdl.interface(TestBPEL)"/>
<binding.ws port="http://xmlns.oracle.com/PatientDataService_jws/Test/TestBPEL#wsdl.endpoint(testbpel_client_ep/TestBPEL_pt)"/>
</service>
I guess it defines the service testbpel_client_ep.But what are the implications of the <interface.wsdl/> and <binding.ws/> tags?In the .componentType file also, the service testbpel_client had the same <interface.wsdl/> tag.
<service name="testbpel_client" ui:wsdlLocation="TestBPEL.wsdl">
<interface.wsdl interface="http://xmlns.oracle.com/PatientDataService_jws/Test/TestBPEL#wsdl.interface(TestBPEL)"/>
</service>
It also intrigues me that both the services(testbpel_client and testbpel_client_ep ) refer to the same wsdl file.I have no clue what is happening.
Thanks in advnceNow the component(testbpel_client_ep) that is being shown in the left swimlane wired to the BPEL process, what is that?I mean is that a service itselfYes. If you check the generate soap service checkbox when defining the BPEL it will generate the service and wiring as you have seen.
Again in the .componentType file, I saw a service was defined but the name of the service defined was testbpel_client.But I didn't define any other service,so where did >that service come from?testbpel_client should be the partner link name for the service. If you open the bpel designer you should see this partner link on the left swim lane. And if you check the wire's in the composite source, you will see that the wire target is testbpel/testbpel_client. Partner Links are by which services and references are referred within the bpel designer.
what are the implications of the <interface.wsdl/> and <binding.ws/> tags?interface.wsdl specifies the wsdl porttype of the interface exposed by bpel.
bindings.ws specifies the wsdl port and soap:location for the bpel. You are not seeing the location part here as this is a service definition and soa runtime will automatically populate this depending upon your deployed environment. This section is more relevant for 'References' coz this is the place you have to modify the endpoint URL's of services you have to invoke. -
Thanks for reading.
I need to export data via SQL to XML. But I need the XML format in Row/column and the output must be a Pivot table. I know that it can be done with AS pivot. But I don't know how to use it in the below script
I've already got a fantastic script with the outcome in Row/Column format, but the output must be in pivot
use Cluster_Data_Mart_NEW
;With CTE
AS
SELECT [Cluster_Name]
,[Cell_Name]
,[Client_Name]
,[Assigned]
FROM CDM_Fact_Personnel_Assigned
INNER JOIN CDM_Dim_Organization on
CDM_Fact_Personnel_Assigned.Organization_Key =
CDM_Dim_Organization.Organization_Key
INNER JOIN CDM_Dim_Client on CDM_Fact_Personnel_Assigned.Client_Key =
CDM_Dim_Client.Client_Key
select
select [Cluster_Name] AS [@name],
(select [Cell_Name] as [column],
null as tmp,
Client_Name as [column],
null as tmp,
Assigned as [column]
from CTE
where [Cluster_Name] = t.[Cluster_Name]
for xml path('row'),type) as [*]
from (select distinct [Cluster_Name] from CTE)t
for xml path('variable'),root('data')
) as col_xml
the above query needs to be in the same XML format(Row/Clolumn) but then in a Pivot table structure.
The desired outcome:
..............CellA...CellB
companyA..4.......3
companyB..0.......4
companyC..1.......2
(whithout the ..............)
The desired outcome in XML:
<data>
<variable name="Cluster_Name">
<row>
<column></column>
<column>CellA</column>
<column>CellB</column>
</row>
<row>
<column>companyA</column>
<column>4</column>
<column>3</column>
</row>
<row>
<column>companyB</column>
<column>0</column>
<column>4</column>
</row>
<row>
<column>companyC</column>
<column>1</column>
<column>2</column>
</row>
</variable>
Is this possible?
Thanks in advance.
Regards,
BartHi Russ,
I
get no error message anymore :) Only is the output not yet as desired.
<data>
<variable name="Cluster_Name">
<row>
<column />
<column>CellA</column>
<column>CellB</column>
</row>
<row>
<column>Company1</column>
<column>CellA</column>
<column>CellB</column>
</row>
<row>
<column>Company2</column>
<column>CellA</column>
<column>CellB</column>
</row>
The desired is the second and third rows need to be the value of the column "Assigned" Like:
<data>
<variable name="Cluster_Name">
<row>
<column></column>
<column>CellA</column>
<column>CellB</column>
</row>
<row>
<column>companyA</column>
<column>4</column>
<column>3</column>
</row>
<row>
<column>companyB</column>
<column>0</column>
<column>4</column>
</row>
<row>
<column>companyC</column>
<column>1</column>
<column>2</column>
Table1: CDM_Fact_Personnel_AssignedColumn1: [Assigned] -> its a number like: 2,3,4,6Table2: CDM_Dim_OrganizationColumn1: [Cluster_Name] Column2: [Cell_Name] -> CellA, CellB
Table3: CDM_Dim_Client Column1: [Client_Name] -> CompannyA, CompannyB
Thanks in advance
Regards,
Bart -
Special character ( , ) in XML Path (' ')
Hi ,
some times my query use the > or < for few records. But XML path is not supporting these values can you please help me with this. Below is the example for what i am working on .
create table #test (id int ,NAME varchar(50),NAME1 varchar(50),NAME2 varchar(50))
insert into #test
values( 1,NULL,'TEST1','TEST1')
,( 2, 'TEST1',NULL,'TEST12')
,( 3,'TEST2','TEST13',NULL)
,( 4,'TEST2 > ', NULL,NULL)
,( 5,NULL,'TEST15',NULL)
,( 6,NULL, NULL, 'TEST6')
,( 7,'TEST8', 'TEST9', 'TEST7')
,( 8,NULL, NULL, NULL)
WITH unpivo AS (
SELECT id, CASE n WHEN 1 THEN NAME
WHEN 2 THEN NAME1
WHEN 3 THEN NAME2
END AS anyname, n
FROM #test
CROSS APPLY (VALUES(1), (2), (3)) AS n(n)
SELECT t.id, CASE WHEN len(u.concat) > 4
THEN substring(u.concat, 1, len(u.concat) -
4)
ELSE ''
END
FROM #test t
CROSS APPLY (SELECT u.anyname + ' AND '
FROM unpivo u
WHERE u.id = t.id
ORDER BY u.n
FOR XML PATH('')) AS u(concat)
where id = 4
DROP TABLE #testNaomi's solution should work well with: FOR
XML PATH(''),
type).value('.','varchar(max)'))
You can concatenate the columns without using XML.
SELECT
Stuff(ISNULL(NAME +' AND ', '')+ISNULL( NAME1 +' AND ', '')+ ISNULL( NAME2+' AND ',''),
len(ISNULL(NAME +' AND ', '')+ISNULL( NAME1 +' AND ', '')+ ISNULL( NAME2+' AND ',''))-3,4,'')
--Or,
Replace(Stuff(ISNULL(NAME +'|', '')+ISNULL( NAME1 +'|', '')+ ISNULL( NAME2+'|',''),
len(ISNULL(NAME +'|', '')+ISNULL( NAME1 +'|', '')+ ISNULL( NAME2+'|','')),1,''), '|',' AND ')
--SQL Server 2012 , 2014
, ISNULL(Replace(Stuff(concat(name+'|', name1+'|',name2+'|' ), Len(concat(name+'|', name1+'|',name2+'|' )),1,''), '|',' AND '),'') from #test
Maybe you are looking for
-
I miss hit and made aol my homepage. How can I return to my previous home page.
I miss hit and made aol my homepage. How can I return to my previous home page. e
-
Unable to open or reinstall addressbook; icon not showing
I'm using a Macbook with Tiger (10.4.11). Tried to open addressbook, but noticed the icon is not the typical brown address book, but the generic "A" icon. Clicking on it does not work. I can open my addresses using the widget & using Mail, but cannot
-
Usefulness of the SAP Netweaver Enterprise Search
I posted this question in the SAP Netweaver Enterprise Search forum and got no response, so I moved it to the ABAP General forum, where I got a little help, but not exactly what I'm looking for, so as a last attempt, I'm moving it here: We are upgrad
-
Where are the av controls on the new QuickTime
Just got my new I Mac and upgraded all systems, in quick time there is no av control where is it?
-
All programs keep "not responding"
I am a new mac user (roughly 6 months) I had tiger for about 2 months before leopard came out. I am not sure where to even start with this. All the programs I use constantly "not respond" Firefox was so buggy I switched to Safari thinking it was FF b