Producing nested xml with querying attributes from a nested table
How can one produce nested xml querying columns from a nested table? Looking at the object documentation, I can readily unnest the tables. Using your examples in the book, unnesting is select po.pono, ..., l.* from purchaseorder_objtab po, table (po.lineitemlist_ntab) l where l.quantity = 2;
what if I don't want to unnest and don't want a cursor. I would like to produce nested xml.
Gail,
Although you can use XSU (XML-SQL Util) in 8.1.7, I would recommend that you upgrade to 9i for much better support (both in functionality and performance) of XML in the database. For example, in Oracle9i there are:
- a new datatype - XMLType for storing and retrieving XML documents
- DBMS_XMLGEN package and SYS_XMLGEN, SYS_XMLAGG functions for generating XML document from complex SQL queries
- A pipelined table function to break down large XML documents into rows.
You can check out some examples using SYS_XMLGEN and DBMS_XMLGEN for your specific needs at http://download-west.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a88894/adx05xml.htm#1017141
Regards,
Geoff
Similar Messages
-
I had an interview question that is:
How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) From another server ex: Transaction server?
Set up steps so inset, update or delete operation takes place across the servers.
It would be great if someone please enlighten me in details about this process in MS SQL Server 2008 R2.
Also please describe would it be different for SQL Server 2012?
If so, then what are the steps?I had an interview question that is:
How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) from another server ex: Transaction server?
Set up steps so that inset, update or delete operation gets done correctly across servers.
I was not sure about the answer, it would be great if someone please put some light on this and explain in details about this process in MS SQL Server 2008 R2.
Also it would be very helpful if you please describe would it be different for SQL Server 2012? If so, then what are the steps? -
I have data in an Oracle8i-database and will use Java to export
it to XML. I’m trying to use XML Developer’s Kit’s (XDK’s) XML
SQL Utility’s (XSU’s) OracleXMLQuery class. But I’ve problems to
get the nested XML-structure I need!
Oracle says there’s two good ways to do this:
“Source Customization
This category incompases customizations done by altering the
query or the database schema. Among the simplest and the most
powerful source customizations are:
* over the database schema, create an object-relational view
which maps to the desired XML document structure.
* in your query, use cursor subqueries, or cast-multiset
constructs to get nesting in the XML document which comes from a
flat schema.”
They then have an example how to create an object-relational
view. But this is done with an empty database, and I already
have tables with data so I don’t know how to do this.
I’ve tried with some simple subqueris like
SELECT name, id,
(SELECT COUNT(*) FROM order o WHERE c.id = o.id) AS
NumOfOrders
FROM cust c
But it adds just another colum.
Could somebody help me or direct me to some resource, please?
Thanks!I have data in an Oracle8i-database and will use Java to export
it to XML. I’m trying to use XML Developer’s Kit’s (XDK’s) XML
SQL Utility’s (XSU’s) OracleXMLQuery class. But I’ve problems to
get the nested XML-structure I need!
Oracle says there’s two good ways to do this:
“Source Customization
This category incompases customizations done by altering the
query or the database schema. Among the simplest and the most
powerful source customizations are:
* over the database schema, create an object-relational view
which maps to the desired XML document structure.
* in your query, use cursor subqueries, or cast-multiset
constructs to get nesting in the XML document which comes from a
flat schema.”
They then have an example how to create an object-relational
view. But this is done with an empty database, and I already
have tables with data so I don’t know how to do this.
I’ve tried with some simple subqueris like
SELECT name, id,
(SELECT COUNT(*) FROM order o WHERE c.id = o.id) AS
NumOfOrders
FROM cust c
But it adds just another colum.
Could somebody help me or direct me to some resource, please?
Thanks! -
Measure using UseRelationship not working well when sliced with attributes from the same table
Hi,
I have Measure created using the 'UseRelationship' Function, which uses a different datekey to link to the DateDim than the one the table is directly related by. The measure works as expected except in one scenario.
If I browse the measure using an attribute from the same fact table then the attribute is filtered using active relationship whereas the measure is filtered using the inactive relationship as shown below:
FACT(2 rows)(Active Relationship to Date using DateKey1)
SNo DateKey1 DateKey2 Geo Amt
1 20100101 20120101 India 100
2 20100101 20120101 US 200
AmtMeasure:=CALCULATE(SUM([Amt]),USERELATIONSHIP(FACT[DateKey2],'Date'[DateKey]))
If I browse the above measure in excel, with Year selected as 2012, I get 100+200=300. Now if I drag the Geo attribute against the measure I get 2 rows with 100 and 200.
If I do the same in a power view report I don't get any results after dragging the Geo attribute, whereas I get the correct value of 300 without the geo attribute. I checked the DAX query which the power view generates and figured this is being caused because
there are no rows in the table with DateKey1 having year 2012. I understand why this is happening this way in a DAX query and not in MDX, but shouldn't both behave in the same way and what is a work around.
Thanks,
Sachin ThomasSac, is this still an issue?
Thank you!
Ed Price, Azure & Power BI Customer Program Manager (Blog,
Small Basic,
Wiki Ninjas,
Wiki)
Answer an interesting question?
Create a wiki article about it! -
Generating nested XML with XSU
Hi,
I have been trying to generate a nested XML document with the
XSU Utility (Rdbms 9.0.1) by setting up an nested table (see below)
and the using the command line utiliy as:
c:\>java OracleXML getXML -user "scott/tiger" "SELECT * from dept_type_tab
The result is nested all right, but all texts seem to be in Hex representation:
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<DEPT>
<DNAME>0x5245534541524348</DNAME>
<EMP>
<ENAME>0x534D495448</ENAME>
</EMP>
</DEPT>
</ROW>
Can anyone point out to me, where I went wrong? ;-(
Thanx for any input
Jan-Peter
create type emp_type as object
ename varchar2(10)
create type dept_type as object
dname varchar2(14),
emp emp_type
create view tmp_jpm2 as
select dept_type(dept.dname,
emp_type(emp.ename)
) dept
from dept, emp WHERE (dept.deptno = emp.deptno);
create table dept_type_tab ( dept dept_type);
insert into dept_type_tab (dept) select dept from tmp_jpm2;Hi,
I have been trying to generate a nested XML document with the
XSU Utility (Rdbms 9.0.1) by setting up an nested table (see below)
and the using the command line utiliy as:
c:\>java OracleXML getXML -user "scott/tiger" "SELECT * from dept_type_tab
The result is nested all right, but all texts seem to be in Hex representation:
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<DEPT>
<DNAME>0x5245534541524348</DNAME>
<EMP>
<ENAME>0x534D495448</ENAME>
</EMP>
</DEPT>
</ROW>
Can anyone point out to me, where I went wrong? ;-(
Thanx for any input
Jan-Peter
create type emp_type as object
ename varchar2(10)
create type dept_type as object
dname varchar2(14),
emp emp_type
create view tmp_jpm2 as
select dept_type(dept.dname,
emp_type(emp.ename)
) dept
from dept, emp WHERE (dept.deptno = emp.deptno);
create table dept_type_tab ( dept dept_type);
insert into dept_type_tab (dept) select dept from tmp_jpm2; -
What's the best way to create XML file with a schema from a database table?
Hi,
I want to create an XML file from a database table (which has over 600 columns) using XML schema (.xsd file). I want to know the best way to do this.
The output XML file is NOT a direct data dump from the DB table, there�re some logic around it, such as the XML file has some hierarchy with repeating tags.
I have done this using JAXB by creating Java classes form XML schema, but I don�t want to map 600 DB columns to these Java classes manually, and loop through the record set to create repeating tags.
I know there are few tools around now like MapForce (Altova), how do people do these now?
Thanks,
ChandiCan you use a schema when we compose XML doc from Database tables?
Actually, I'm using SQL Server (sorry, wrong forum). But, I thought a Java tool would have a solution for me. -
Logical table with data restrictions from the physical table
Hello, I have a question about the relationships between the Logical Tables in Business Model and Mapping and The Physical table in the physical layer. The problem is the next one:
I have a Physical Table named T1 that contains the attributes: Id, DateChangeState, State,…
T1
DateChangeState| ID |State | Other columns….
01/01/2011 | 1 | 03 | …
02/01/2011 | 1 | 11 | …
03/01/2011 | 1 | 02 | …
02/02/2011 | 2 | 01 | …
03/02/2011 | 2 | 02 | …
I need filter this table and extract only one row per ID. The row that I need is the row who contains the Max(DateChangeState) per ID. I don’t know how extract only the rows selected from the physical table to the Logical Table.
I need that the logical table contains the next rows:
T1_Logical
DateChangeState |ID | State Other columns….
03/01/2011 | 1 | 02 | …
03/02/2011 | 2 | 02 | …
How can I extract only the rows with the Max(DateChangeState) grouped by ID in the BMM?
I thought put this condition in the column mapping (CASE WHEN DateChangeState=Max(DateChangeState)) but the Max(DateChangeState) was not grouped by ID.
Any idea about how solve this problem?
I can not use the group by in the answer and I can not change the physical layer.
Thank you,
Best Regards.Hi Rajeevagrl your solution is very good but I dont´t know why obiee is applying twice the max condition, The select is the next one:
select distinct D1.c1 as c1,
D1.c2 as c2,
D1.c1 as c3
from
(select D1.c1 as c1,
D1.c2 as c2
from
(select D1.c1 as c1,
D1.c2 as c2,
max(D1.c3) over () as c3
from
(select T379.ID as c1,
T379.DATE as c2,
max(T379.DATE) as c3
from
T1 T379
group by T379.ID, T379.DATE
) D1
) D1
where ( D1.c2 = D1.c3 )
) D1
order by c2
Edited by: 848497 on 14-abr-2011 3:58 -
Help with querying a 200 million record table
Hi ,
I need to query a 200 million record table which is partitioned by monthly activity.
But my problem is I need to see how many activities occured on one account in a time frame.
If there are 200 partitions, I need to go into all the partitions, get the activities of the account in the partition and at the end give the number of activities.
Fortunately, only activity is expected for an account in the partition which may be present or absent.
if this table had 100 records, i would use this..
select account_no, count(*)
from Acct_actvy
group by account_no;Must stress that it is critical that you not write code (SQL or PL/SQL) that uses hardcoded partition names to find data.
That approach is very risk, prone to runtime errors, difficult to maintain and does not scale. It is not worth it.
From the developer's side, there should be total ignorance to the fact that a table is partitioned. A developer must treat a partition table no different than any other table.
To give you an idea.. this a copy-and-paste from a SQL*Plus session doing what you want to do. Against a partitioned table at least 3x bigger than yours. It covers about a 12 month period. There's a partition per day - and empty daily partitions for the next 2 years. The SQL aggregation is monthly. I selected a random network address to illustrate.
SQL> select count(*) from x25_calls;
COUNT(*)
619491919
Elapsed: 00:00:19.68
SQL>
SQL> select TRUNC(callendtime,'MM') AS MONTH, sourcenetworkaddress, count(*) from x25_calls where sourcenetworkaddress = '3103165962'
2 group by TRUNC(callendtime,'MM'), sourcenetworkaddress;
MONTH SOURCENETWORKADDRESS COUNT(*)
2005/09/01 00:00:00 3103165962 3599
2005/10/01 00:00:00 3103165962 1184
2005/12/01 00:00:00 3103165962 4
2005/06/01 00:00:00 3103165962 1
2005/04/01 00:00:00 3103165962 560
2005/08/01 00:00:00 3103165962 101
2005/03/01 00:00:00 3103165962 3330
7 rows selected.
Elapsed: 00:00:19.72As you can see - not a single reference to any partitioning. Excellent performance, despite running on an old K-class HP server.
The reason for the performance is simple. A correctly designed and implemented partitioning scheme that caters for most of the queries against the table. Correctly designed and implemented indexes - especially local bitmap indexes. Without any hacks like partition names and the like... -
I have Oracle 10g . In a table with just one record there is a a clob with the following xml.
<container>
<param name="paramA" value="valueA" />
<param name="paramB" value="valueB" />
</container>
How can I enumerate paramA, paramB from above?Your query neglected to show the error message you were getting, which should have been
select x.paramName, x.paramValue
from test_xml t
, xmltable('/container/param'
passing xmltype(t.xmlcontent)
columns
paramName varchar2(30) path '@type'
, paramValue varchar2(80) path '@value') x
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00234: namespace prefix "xsi" is not declared
Error at line 2
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at line 1Taking that, you would ask yourself how to declare the namespace and some searching would eventually turn up that
1) your sample XML is invalid as it does not have a namespace prefix defined for xsi
2) You need to use XMLNamespaces within the [url http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions228.htm#SQLRF06232]XMLTable function
Putting those together and assuming you mean the standard URI for the xsi prefix, your sample XML should look like
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<param xsi:type="paramA" value="valueA"/>
<param xsi:type="paramB" value="valueB"/>
</container>and the query would look like
select x.paramName, x.paramValue
from test_xml t
, xmltable(XMLNamespaces('http://www.w3.org/2001/XMLSchema-instance' as "xsi"),
'/container/param'
passing xmltype(t.xmlcontent)
columns
paramName varchar2(30) path '@xsi:type'
, paramValue varchar2(80) path '@value') x; -
How do i query attributes from xml documents
I want to to query only details in Issue id="705230" (id is an attribute)
I tried this, but does not help. I should be able to query the value of core_org_id attribute
select extract(CLOB_DATA, 'PcrDocument/PcrOrganization/core_org_id) CORE_ORG_ID from from pcr_files where existsNode(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue[@id="705230"]')=1;
-- does not return anything....
I tried to extract value for R_DATE & R_REVIEW_DATE for issue id=705230, but iam not able to.
Data for all the issues is retured.
Here is the query used...
select extract(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue') ISSUE from pcr_files where existsNode(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue[@id="705230"]')=1;
Here is the part of XML document iam querying on...
- <ns1:PcrDocument id="PCR-13562" title="EU Disclosures - EC 1060/2009" version="1" pcrPublishDate="2012-01-11T12:49:02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://integration.mysite.com/ServiceSchema/v3">
- <ns1:PcrOrganization core_org_id="345840">
<ns1:PcrLinkedTo value="ISSUE" />
- <ns1:AdditionalInfo>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:Issues>
- <ns1:Issue id="705230">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:IssueDetail id="114766798">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
- <ns1:Issue id="727193">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:IssueDetail id="117994574">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
</ns1:Issues>
</ns1:PcrOrganization>
</ns1:PcrDocument>I did not include the name space declaration for it is working fine. Really? Then I suppose you must be using a schema-based XMLType column?
Is it Object-Relational or Binary XML storage?
You mentioned it is depricated in 11.2, but iam able to run it on 11.2.Deprecated doesn't mean it ceases functioning.
Any suggestions to covert this to XMLTable/XMLQuery format please..If you read the documentation, it covers this part too ;)
Example :
create table tmp_xml of xmltype;
insert into tmp_xml values(
xmltype('<ns1:PcrDocument id="PCR-13562" title="EU Disclosures - EC 1060/2009" version="1" pcrPublishDate="2012-01-11T12:49:02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://integration.mysite.com/ServiceSchema/v3">
<ns1:PcrRatingDetails>
<ns1:LeadAnalyst>
<ns1:FirstName>xxxxx</ns1:FirstName>
<ns1:MiddleName/>
<ns1:LastName>xxxxxx</ns1:LastName>
<ns1:Title>Director</ns1:Title>
<ns1:Label>Primary Analyst</ns1:Label>
<ns1:Telephone>xxxxxxxxxxxx</ns1:Telephone>
<ns1:Email>[email protected]</ns1:Email>
<ns1:Address>
<ns1:Line1>Main Tower</ns1:Line1>
<ns1:Line2>Neue Mainzer Strasse</ns1:Line2>
<ns1:City>FFT</ns1:City>
<ns1:State/>
<ns1:ZipCode>99999</ns1:ZipCode>
<ns1:Country>Germany</ns1:Country>
</ns1:Address>
</ns1:LeadAnalyst>
<ns1:RatingApprover>
<ns1:FirstName>Nick</ns1:FirstName>
<ns1:MiddleName/>
<ns1:LastName>Mate</ns1:LastName>
</ns1:RatingApprover>
</ns1:PcrRatingDetails>
<ns1:PcrOrganization core_org_id="345840">
<ns1:PcrLinkedTo value="ISSUE"/>
<ns1:AdditionalInfo>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:Issues>
<ns1:Issue id="705230">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:IssueDetail id="114766798">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
<ns1:Issue id="727193">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:IssueDetail id="117994574">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
</ns1:Issues>
</ns1:PcrOrganization>
</ns1:PcrDocument>')
SQL> set long 10000
SQL>
SQL> select x1.analyst
2 , x1.chair
3 , x1.core_org_id
4 , x2.*
5 from tmp_xml t
6 , xmltable(
7 xmlnamespaces(default 'http://integration.mysite.com/ServiceSchema/v3')
8 , '/PcrDocument'
9 passing t.object_value
10 columns analyst xmltype path 'PcrRatingDetails/LeadAnalyst'
11 , chair xmltype path 'PcrRatingDetails/RatingApprover'
12 , core_org_id number path 'PcrOrganization/@core_org_id'
13 , issues xmltype path 'PcrOrganization/Issues/Issue'
14 ) x1
15 , xmltable(
16 xmlnamespaces(default 'http://integration.mysite.com/ServiceSchema/v3')
17 , '/Issue'
18 passing x1.issues
19 columns issue number path '@id'
20 , rating_date varchar2(40) path 'AdditionalInfo/Info[@type="R_DATE"]'
21 , rating_review_date varchar2(40) path 'AdditionalInfo/Info[@type="R_REVIEW_DATE"]'
22 , issue_detail number path 'IssueDetail/@id'
23 , id_rating_date varchar2(40) path 'IssueDetail/AdditionalInfo/Info[@type="R_DATE"]'
24 , id_rating_review_date varchar2(40) path 'IssueDetail/AdditionalInfo/Info[@type="R_REVIEW_DATE"]'
25 ) x2
26 where x2.issue = 705230
27 ;
ANALYST CHAIR CORE_ORG_ID ISSUE RATING_DATE RATING_REVIEW_DATE ISSUE_DETAIL ID_RATING_DATE ID_RATING_REVIEW_DATE
<LeadAnalyst xmlns="http://integration.mysite.com/ServiceSchema/v3"> <RatingApprover xmlns="http://integration.mysite.com/ServiceSchema/v3"> 345840 705230 Credit Release Date: 09-Apr-2010 Credit Last Review Date: 12-Oct-2011 114766798 Credit Release Date: 09-Apr-2010 Credit Last Review Date: 12-Oct-2011
<FirstName>xxxxx</FirstName> <FirstName>Nick</FirstName>
<MiddleName/> <MiddleName/>
<LastName>xxxxxx</LastName> <LastName>Mate</LastName>
<Title>Director</Title> </RatingApprover>
<Label>Primary Analyst</Label>
<Telephone>xxxxxxxxxxxx</Telephone>
<Email>[email protected]</Email>
<Address>
<Line1>Main Tower</Line1>
<Line2>Neue Mainzer Strasse</Line2>
<City>FFT</City>
<State/>
<ZipCode>99999</ZipCode>
<Country>Germany</Country>
</Address>
</LeadAnalyst> -
Un-nest XML with single child element
I'm trying to write a generic function for un-nesting child nodes where nesting is deemed unnecessary. Typically when the element only has one child element.
For example, given the following source....
<ROOT>
<ITEM>
<DESCRIPTION>TEST1</DESCRIPTION>
</ITEM>
<ITEM>
<DESCRIPTION>TEST2</DESCRIPTION>
</ITEM>
</ROOT>I actually want.....
<ROOT>
<DESCRIPTION>TEST1</DESCRIPTION>
<DESCRIPTION>TEST2</DESCRIPTION>
</ROOT>because we think ITEM isn't really required before we deliver XML data.
I've been trying to achieve this with a function, where I pass in the XPath to the node I want flattening, something like
function UnNest(pXMLData XMLType, pXPath varchar2) return XMLType...Called like the following...
declare
begin
vXMLData := UnNest(SomeXMLData, '/ROOT/ITEM')
end;I tried using XQuery Update (11gR2), as follows,
select /*+ no_xml_query_rewrite */
xmlquery('
copy $d := .
modify (
for $i in $d/ROOT/ITEM
return
replace node $i with $i/child::node()
return $d'
passing xmltype(
'<ROOT>
<ITEM>
<DESCRIPTION>TEST1</DESCRIPTION>
</ITEM>
<ITEM>
<DESCRIPTION>TEST2</DESCRIPTION>
</ITEM>
</ROOT>'
returning content) XML
from dual.... which works, but when I try to pass in a path variable, it doesn't.
select /*+ no_xml_query_rewrite */
xmlquery('
copy $d := .
modify (
for $i in $d/$Unnestpath
return
replace node $i with $i/child::node()
return $d'
passing xmltype(
'<ROOT>
<ITEM>
<DESCRIPTION>TEST1</DESCRIPTION>
</ITEM>
<ITEM>
<DESCRIPTION>TEST2</DESCRIPTION>
</ITEM>
</ROOT>'
'ROWSET/ROW' as "Unnestpath"
returning content) XML
from dual
ORA-19112: error raised during evaluation:
XVM-01020: [XPTY0020] The path step context item is not a node
6 replace node $i with $i/child::node()
- ^Am I missing something obvious?
My destination platform is 11gR2 64 bit but going forward I may need a solution for 10gR2 too. Perhaps there is another way without using XQuery Update? Any advice would be greatly appreciated.paul zip wrote:
when I try to pass in a path variable, it doesn't.Yes, paths are not variables, they have to be static. However, you can make the whole query dynamic.
Another option is XSLT, which will work on both releases, or a combination of extract/updatexml calls.
SQL> create or replace function UnNest(pXMLData XMLType, pXPath varchar2)
2 return XMLType
3 is
4 result XMLType;
5 xsl_template varchar2(2000) :=
6 '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7 <xsl:template match="@*|node()">
8 <xsl:copy>
9 <xsl:apply-templates select="@*|node()"/>
10 </xsl:copy>
11 </xsl:template>
12 <xsl:template match="#TARGET_XPATH#">
13 <xsl:apply-templates select="node()"/>
14 </xsl:template>
15 </xsl:stylesheet>';
16
17 begin
18
19 select xmltransform(
20 pXMLData
21 , xmlparse(document replace(xsl_template, '#TARGET_XPATH#', pXPath))
22 )
23 into result
24 from dual ;
25
26 return result;
27
28 end;
29 /
Function created
SQL> set long 5000
SQL>
SQL> select unnest(
2 xmltype(
3 '<ROOT>
4 <ITEM>
5 <DESCRIPTION>TEST1</DESCRIPTION>
6 </ITEM>
7 <ITEM>
8 <DESCRIPTION>TEST2</DESCRIPTION>
9 </ITEM>
10 </ROOT>'),
11 '/ROOT/ITEM'
12 )
13 from dual;
UNNEST(XMLTYPE('<ROOT><ITEM><D
<ROOT>
<DESCRIPTION>TEST1</DESCRIPTION>
<DESCRIPTION>TEST2</DESCRIPTION>
</ROOT>
Typically when the element only has one child element.If it's a general rule to apply, XSLT can do it very easily on every node that satisfies this condition.
Edited by: odie_63 on 21 mai 2013 12:38 -
Help with Retrieve attributes from database
Hi,
I'm using filter "Retrieve from or write to database" with select query from database by selecting attributes as column names radio button.
I'm unable to get these user attributes with column names.
For eg : select tag from test_tag where rownum=1;
I was trying so that result can be used using tag attribute (${tag}).
Please help in this regard.
Thanks,
VaniHi Vani,
After the retrieve filter, add a Trace Filter and leave it as it is. Execute the policy once and in the trace data that now will be displayed there you should be able to read out the exact name and type of the parameter. This way of identifying data/parameters etc is a recommended way of working while developing! Copy paste the Trace Data from the Trace filter here if you need help!
Cheers,
Stefan -
Need to create new users in Office 365 with custom attributes from a csv file
I am exporting users from an active directory environment and then deleting them from AD. They are Alumni and will no longer be in AD.
I have a csv file with the following fields that I need to use to create new Alumni email boxes in Office 365 for. I need the CustomAttributes because my Dynamic Distribution Groups use them. I am fairly new to PowerShell and have been unable to get this
to work. I suspect I may have to split it into two parts, but am not sure how to proceed. Any assistance would be appreciated. I was directed here from the Office 365 community.
Import-Csv -Path c:\CSVfiles\CreateAlumni.csv | ForEach-Object {
New-MsolUser -FirstName $_.FirstName -LastName $_.LastName
-UserPrincipalName $_.UserPrincipalName
-DisplayName "$($_.FirstName) $($_.LastName)"
-Password $_.Password
-CustomAttribute1 $_.CustomAttribute1
-CustomAttribute3 $_.CustomAttribute3
-CustomAttribute10 $_.CustomAttribute10
-CustomAttribute11 $_.CustomAttribute11
-CustomAttribute12 $_.CustomAttribute12
-LicenseAssignment 'domaincom:EXCHANGESTANDARD_ALUMNI'
-UsageLocation USOk, it wasn't stopping after 2 iterations. What I was seeing was 2 failures. The first was the Get-Mailbox command and the second was when it tried to assign attributes. For some reason it is not looping when it fails. It just goes on and tries to assign
the Custom Attributes. I added writes in to tell me what was happening.
### Check if mailbox is provisioned yet
Write-Host "Checking if mailbox is provisioned yet..." -foregroundcolor yellow
$found = $false
$count = 0
Do {
try {
Get-Mailbox -Identity $_.UserName -ErrorAction Stop
$found = $true
Write-Output 'Mailbox found. Details:'
Get-Mailbox -Identity $_.UserName
} catch {
Write-Output 'Sleeping'
$count++
Start-Sleep -Seconds 5
If ($count -ge 12) {
Write-Output 'Mailbox not found. Quitting.'
$found = $true
} Until ($found)
Write-Host "Adding Custom Attributes to User" -foregroundcolor yellow
Set-Mailbox -Identity $_.UserName -CustomAttribute1 $_.CustomAttribute1 -CustomAttribute3 $_.CustomAttribute3 -CustomAttribute10 $_.CustomAttribute10 -CustomAttribute11 $_.CustomAttribute11 -CustomAttribute12 $_.CustomAttribute12
Write-Output "User has been Provisioned in Office 365!" -foregroundcolor yellow
Checking if mailbox is provisioned yet...
The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
+ CategoryInfo
: NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=e1aabda1-01e4-4f68-984e-e20be0975242,TimeStamp=5/22/2014 4:23:59 AM] [FailureCategory=Cmdlet-ManagementObj
ectNotFoundException] 2788FB48,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
+ PSComputerName : pod51038psh.outlook.com
Mailbox found. Details:
The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
+ CategoryInfo
: NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=16a8a2bc-333a-455c-8504-e0b99c44c334,TimeStamp=5/22/2014 4:24:00 AM] [FailureCategory=Cmdlet-ManagementObj
ectNotFoundException] 2788FB48,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
+ PSComputerName
: pod51038psh.outlook.com
Adding Custom Attributes to User
The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
+ CategoryInfo
: NotSpecified: (:) [Set-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=8319d220-b9dd-492f-8182-5083cf56e58b,TimeStamp=5/22/2014 4:24:00 AM] [FailureCategory=Cmdlet-ManagementObj
ectNotFoundException] C7844A24,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
+ PSComputerName
: pod51038psh.outlook.com
User has been Provisioned in Office 365!
Of course the user has been provisioned, but the CustomAttributes have not been assigned. :( -
Referencing a page item with query results from another page
Hello Gurus,
Any Idea How to achieve following in APEX.
Step 1: Page 1, Region A of type SQL report.
Sql query:
select employee from emp;Step 2: Page 2, A display item is created on this page, say :P2_X that is intended to source its values from the query/region written in Page1.
In this example stated above, I need to display :P2_X on PAGE 2 that in receives value from employee column on the query mentioned in step 1.
Any idea how to achieve this?
Thank you for reading this post.
-RHello Rich,
Edit your SQL Report.
Under Column Attributes , edit the EMPLOYEE Column.
Go to LINK Tab.
In link text : select the first option #EMPLOYEE#
In Target is - select Page in this application.
in item type P1_X and in value enter #EMPLOYEE#
Regards,
Shijesh -
Populate hierarchical tree with Query "Select * from EMP"
Dear(S)
I want to populate a Hierarchical Tree to display results
in a well alligned form as results usually display in SQL Plus environment.
I try much using LPAD() and RPAD() function but fail to get required results.
I want to display more than one field values by concatenating them.
e.g.
SMITH CLERK 800
ALLEN SALESMAN 1600
WARD SALESMAN 1250
JONES MANAGER 2975
Please someone guide me how i can allign more than one field values in a Hierarchical tree.
Thanks and regards,
Tanveer Ahmad.Dear Thiru,
I have successfully populate the tree
but i want to display these fields at a specific distance.
How i can do it? (I have try it with LPAD() and RPAD() but fail.)
Thanks
Tanveer
Maybe you are looking for
-
Contract update with reference to an order
Hello everybody, I'm trying to find a way to update the contract value released (AWERT field in RV45A structure) when an additional order is created with reference to an existing one. Thank you in advance. Mike Edited by: Michael Papadakis on Dec 22,
-
Import Files as Projects makes other projects disappear
Hi, I'm new to these forums and new to Aperture. I would really like some help with this issue. I have searched the forums and while I've found one other post with the exact problem no one has posted an answer...I hope for better results. I work in I
-
Hi all, is there any user-exit or BADI to default the header text(not item text) in MIGO to PO header text. Thanks regards, sap fan.
-
I have the old airport express but my iPad 3 is not able to connect to it even with the app downloaded. What can I do?
-
There is a bapi BAPI_BUPA_CREATE_FROM_DATA for creation of business partners. I need to extend this bapi by adding few custom fields. What is the method to follow inorder to extend this bapi and please give me the procedure so that it helps me... Tha