Reg: XQuery/XPath expr.
Hi Experts,
I was trying to learn/experience the XQuery/XPath expressions and had some doubts.
I learn here-http://www.w3schools.com/xquery/xquery_example.asp
Configuration script:
CREATE TABLE a (col1 XMLTYPE);
INSERT INTO a VALUES (XMLTYPE ("<?")) XML version = "1.0" encoding ="ISO-8859-1"? >
< library >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > Giada De Laurentiis < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "CHILDREN" >
< title lang = "fr" > Harry Potter < /title >
< author > J K Rowling < / author >
< year > 2005 < / year >
< price > 29.99 < / price >
< / book >
< Book category = "WEB" >
< title lang = "fr" > XQuery Kick Start < /title >
< author > James McGovern < / author >
< author > per Bothner < / author >
< author > Kurt Cagle < / author >
< author > James Linn < / author >
< author > Vaidyanathan Nagarajan < / author >
< year > 2003 < / year >
< price > 49.99 < / price >
< / book >
< Book category = "WEB" >
< title lang = "fr" > Learning XML < /title >
< author > Erik T. Ray < / author >
< year > 2003 < / year >
< price > 39.95 < / price >
< / book >
((< / book > '));
It worked:
RANIT@XE11GR2 > > ed
A written file afiedt.buf
1 Select xt.colx
2 a, XMLTable ('/ bookstore/book[price < 40]')
3 passage a.col1
4 columns
5 way XMLTYPE colx '.'
6 *) xt
RANIT@XE11GR2 > >.
COLX
----------------------------------------------------------------------------------------------------------------------------------
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > Giada De Laurentiis < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "CHILDREN" >
< title lang = "fr" > Harry Potter < /title >
< author > J K Rowling < / author >
< year > 2005 < / year >
< price > 29.99 < / price >
< / book >
< Book category = "WEB" >
< title lang = "fr" > Learning XML < /title >
< author > Erik T. Ray < / author >
< year > 2003 < / year >
< price > 39.95 < / price >
< / book >
Elapsed time: 00:00:00.16
But when tried to join another filter condition, it gives me the error:
RANIT@XE11GR2 > > ed
A written file afiedt.buf
1 Select xt.colx
2 a, XMLTable ('/ bookstore/book[< 40 year AND price < 2004]')
3 passage a.col1
4 columns
5 way XMLTYPE colx '.'
6 *) xt
RANIT@XE11GR2 > >.
a XMLTable ('/ bookstore/book [price < 40 year AND < 2004] ")
*
ERROR on line 2:
ORA-19114: XPST0003 - error during parsing of the XQuery expression:
LPX-00801: to "AND" XQuery syntax error
1/bookstore/book [price < 40 year AND < 2004]
- ^
Elapsed time: 00:00:00.04
RANIT@XE11GR2 > > ed
A written file afiedt.buf
1 Select xt.colx
2 a, XMLTable ('/ bookstore/book[price < year 40, < 2004]')
3 passage a.col1
4 columns
5 way XMLTYPE colx '.'
6 *) xt
RANIT@XE11GR2 > >.
ERROR:
ORA-19169: FORG0006: invalid argument in «fn:boolean()» type
no selected line
Elapsed time: 00:00:00.20
Could you please help me how to add multiple condition filter here?
Thank you
-Nordine
(on Oracle 11.2.0.3.0)
There "and" lowercase:
/ bookstore/book [price<40 and="">40><>
If I may ask another site to start learning: Tutorials of XQuery
And of course, the W3C recommendation official, always useful to get information about the base language: http://www.w3.org/TR/xquery/
For the Oracle specifics, see DB XML Dev Guide:
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb_xquery.htm
Also, as you should know by now, this kind of questions belong to the forum DB XML or XQuery forum (for a general discussion of the language).
Tags: Database
Similar Questions
-
Retrieve XDB$ index not the text ENUM_T values
All,
I have a type xdb xml element $ enum_t where I can't find a way to get the text associated with the index value. The only way I seem to be able to get the index value is through the point object relationship (.value) notation. It gives me the index value of the list of restriction. I saw another post referring to the same question, but never responded. I need this xml element limited by this list. Any help or ideas appreciated. I'm using Oracle 11 g.
Thank you
Tom
Hi Tom,
It is not the right approach for what you are trying to reach.
XDB$ ENUM_T is internal stuff that is not intended to be handled directly.
Always use the XQuery/XPath functions to access the node values.
I need this xml element limited by this list.
What you mean?
Object-relational storage via an XML schema that you use? If so, what is the problem?
Could you put a small suitcase to test?
Thank you.
-
How to get the Max of elements of type datetime value
Hi all
I wanted to get the last value timestamp (DateTime data type) of the node list. I have the following xml. In this xml file, I want to get the modifydate element that has the last time stamp via xquery/xpath, it should return me following result 2011-09-29 T 17: 21:17 + 10:00
< CustomerList >
< CustomerDetails >
< Name > Test 1 < / name >
assets of < status > < / status >
< modifyDate > 2011-08-20T 17: 21:17 + 10:00 < / modifyDate >
< / CustomerDetails >
< CustomerDetails >
< Name > Test 2 < / name >
Cancel < status > < / status >
< modifyDate > 2011-08-29T 17: 21:17 + 10:00 < / modifyDate >
< / CustomerDetails >
< CustomerDetails >
< Name > Test 3 < / name >
assets of < status > < / status >
< modifyDate > 2011-09-29T 17: 21:17 + 10:00 < / modifyDate >
< / CustomerDetails >
< / CustomerList >
I tried to use the
CustomerList/CustomerDetails/modifyDate [not (. < =... / the above - sibling:CustomerList/CustomerDetails modifyDate) and not (. < =... / following - sibling:CustomerList/CustomerDetails modifyDate)]
But it does not work on the datetime data type.
Any help in this regard is highly appreciated.
Concerning
Published by: user6736659 on Sep 5, 2011 06:15Hello
The following XQuery query should give you what you want:
max( for $i in /CustomerList/CustomerDetails/modifyDate return xs:dateTime($i) )
For example, by using Oracle SQL:
SQL> var xmldoc varchar2(4000) SQL> begin 2 :xmldoc := '
3 '; 21 end; 22 / PL/SQL procedure successfully completed SQL> select xmlquery('max( 2 for $i in /CustomerList/CustomerDetails/modifyDate 3 return xs:dateTime($i) 4 )' 5 passing xmltype(:xmldoc) 6 returning content 7 ) 8 from dual 9 ; XMLQUERY('MAX(FOR$IIN/CUSTOMER -------------------------------------------------------------------------------- 2011-09-29T17:21:17.000000+10:004 8 9Test 1 5active 62011-08-20T17:21:17+10:00 710 14 15Test 2 11cancel 122011-08-29T17:21:17+10:00 1316 20Test 3 17active 182011-09-29T17:21:17+10:00 19 -
Standares are taken care of by OBPM 10 g and 11g OBPM.
I read an article on OSB. It supports the following standards:
• SOAP 1.1, SOAP 1.2, WSDL 1.1 and WSDL 1.1 Binding Extension for SOAP 1.2, SOAP with attachments
• WS-Security 1.0/1.1, WS-SecurityPolicy, WS-Policy, WSPolicyAttachment, WS-Security: Username Token Profile 1.0/1.1, WS-Security: X.509 WSSecurity 1.0/1.1 token profile: 1.0/1.1, WS-Security SAML token profile: Kerberos Token Profile 1.1,.
• 1.0 Messaging WS-Reliable, WS-Addressing, WS - I Basic Profile 1.1
• REST
• MTOM / XOP
• XSLT 1.0, XQuery, XPath 2.0
• Interoperability with UDDI v3 compliant registries and JMS/MQ-based middleware
• HTTP 1.0, HTTP 1.1, TLS, SSL
What article lists taken standards supported by OBPM 10 or 11g?
Thank youWeb
Comes from a few years ago and watch the standards supported by BPM Oracle 10 g. An Oracle person would need to update and to provide information on Oracle 11 g BPM.
User interface / Web Standards
JSTL 1
JSP 1.2
Servlet 2.4
JSF 1.1
Facelets 1.1.12
Web Service standards
HTTP 1.1
SOAP 1.1
XML 1
WSDL 1.1
UDDI 3
WS-Security 1.1
Username token profile 1BPM standards
XPDL XPDL 2.0 + Extensions
BPMN BPMN 1.1 -
Reg: Difference between XQuery and XPath:
Hi Experts,
I tried google on this subject and read a few articles but found no adequate explanation or may not be able to understand.
Of http://stackoverflow.com/questions/924551/difference-between-xpath-xquery-and-xpointer
In general, XPath is a language used to locate accurate XML nodes in a DOM succinctly. XQuery is a superset of XPath which also provides FLWOR sytnax, which is similar to SQL. Finally, XPointer includes XPath, but also provides a simple model to address based on the post.
It is also a good read - what is XQuery?
Any other pointers? According to my understanding, both are used for the XMLs, like the SQL query for relational data. But if the two are similar, what is the reasoning behind the two different technologies?
Please share your ideas in this regard.
Kind regards
-Nordine
(on Oracle 11.2.0.3.0)
Basic functions?
http://www.w3.org/TR/XPath/#corelib
Typing?
http://www.w3.org/TR/xpath20/#ID-types
"Transforming data" - you mean CFDS on XML data, right?
More like SQL, but there is no strict equivalence.
Given that XML is self-descriptive language, transforming one XML document into another also means the metadata change.
This is where the concept of XML schema.What language do technical FLWOR come - XQuery or XPath?
XQuery.
For example:
for $i in/root/point [1] / value
where $i/@uom = 'kg '.
Return to{data ($i)} applied to this XML document:
123
will return this sequence:
123 Here, / root/point [1] / value is an XPath expression (which is also an XQuery expression) but the construction of FLWOR is strictly XQuery.
-
XQuery insert node and assign the value based on an XPATH expression
Hello
I am trying to write a function that receives an XML as input parameters and return updated XML output
-nodes are removed from the input XML code
-a node must be inserted and the node value must be 1 or 0, based on an XPATH expression
I discovered how to remove nodes, I discovered how to insert a new node, but I can not set the value of the conditionally inserted node an XPATH expression.
Here's my current procedure and below a sample of one XML of entry. I use Oracle 12 c.
CREATE OR REPLACE FUNCTION STRIP_XML ( IN_XML IN SYS.XMLTYPE ) RETURN SYS.XMLTYPE AS p_result XMLType; BEGIN select xmlquery( 'declare default element namespace "http://mad.evs.com/search"; (: :) copy $d := . modify ( delete node $d//MainCategory/@logId, delete node $d/MainCategory/@id, -- a lot more of those delete node -- insert a node, but the value 1 is conditional insert node <DMZ>1</DMZ> after $d/MainCategory/SDataSection/EventDate) return $d' passing in_xml returning content ) into p_result from dual; RETURN p_result; END STRIP_XML;
The condition for the value of is
HASPATH (//DigitalAssets/DigitalAsset [@ available = "true" and @videoFormatId = "11"] / VideoLocations/Videorental [@typeId = "8"]) then 1 else 0
It is complex because DigitalAssets/DigitalAsset is a collection. Here is an example of an XML to entry
<MainCategory xmlns="http://mad.evs.com/search" id="9" logId="3349" logType="3"> <Name>Sport</Name> <Serie id="163" externalId="557"> <TitleAKA>UCL 2006/07</TitleAKA> <DigitalAssets available="true" som="20:28:49:05" dur="00:02:46:04" videoDurationMinutes="3"> <DigitalAsset available="true" som="20:28:49:05" dur="00:02:46:04" videoDurationMinutes="3" videoFormatId="3"> <VideoLocations> <VideoLocation id="3" path="003349MA.mxf" typeId="1" locationId="1" priority="0"/> <VideoLocation id="3" path="003349MA.mxf" typeId="2" locationId="1" priority="0"/> <VideoLocation id="3" path="003349MA.mxf" typeId="5" locationId="1" priority="0"/> </VideoLocations> </DigitalAsset> <DigitalAsset available="true" som="20:28:49:05" dur="00:02:46:04" videoDurationMinutes="3" videoFormatId="11"> <VideoLocations> <VideoLocation id="101" path="003349MA.mpg" typeId="1" locationId="1" priority="0"/> <VideoLocation id="101" path="003349MA.mpg" typeId="2" locationId="1" priority="0"/> <VideoLocation id="101" path="003349MA.mpg" typeId="8" locationId="1" priority="0"/> </VideoLocations> </DigitalAsset> </DigitalAssets> <SDataSection xmlns="http://mad.evs.com/search"> <EventDate>2006-08-09</EventDate> <LogType>3</LogType> </SDataSection> </MainCategory>
In this case, because HASPATH expression could be set to true, the value of the added node must be 1.
Any help or advice how I should fight against that would be appreciated. I have no experience with XML and XQuery, I create my function through from trial and error of the doc.
Thanks and regards, Pierre
Hi Pierre,.
You can use the if-then-else statement, like this:
Insert the node
{
If ($d/MainCategory/DigitalAssets/DigitalAsset[@available="true' and @videoFormatId = '11'] / VideoLocations/Videorental [@typeId = '8'])
then 1
0 otherwise
}
After $d, MainCategory, SDataSection, EventDate
XSLT can be an alternative to the XQuery Update in this case.
-
How to divide a variable in 3 of those using the XPath/XQuery functions
Hello
do you know if it is possible to divide a (string) variable with this format, var1, var2 > < var3 > in 3 simple variables such as:
var1;
var2;
var3;
use of XPath/XQuery functions in a project of OSB?
I found how to get the same result by using an action of legend of java, but I prefer an easier way (if available).
Thank you.
Hello
Take a look at this section of forum...
https://forums.Oracle.com/thread/1274460
See you soon,.
Vlad
-
Hello
1. can differentiate you these XSLT, XPath and XQuery.
2. How can I force a Rollback in a BPEL workflow.
Thanks in advanceShree says:
1. can differentiate you these XSLT, XPath and XQuery.XSL stands for EXtensible Stylesheet Language is a language of style sheet for XML documents. XSLT stands for XSL Transformations.
XQuery is to XML SQL format to database tables. XQuery is designed to query XML data.
XPath is used to navigate through elements and attributes in an XML document. XPath is a major element of trailer of the W3C XSLT - and XQuery and XPointer are both built on XPath expressions.http://www.w3schools.com/xsl/default.asp
http://www.w3schools.com/XQuery/default.asp
http://www.w3schools.com/XPath/default.aspSee you soon,.
Vlad -
OSB: xpath as a result of the XQuery output?
Hello
I have a related XML non-schema as input. Value of one of the tags will be 'KEYWORD'.
I want a dynamic text 'Hello' instead of the KEYWORD.
From now I convert XML to a string with fn - bea: serialize() and then create a fn: replace.
Viz:
Let $received_input: = KEYWORD < C > < D >/< d: > < / c >
Let $convertedXML: = fn-serialize ($received_input)
Let $temp_string: = fn:replace($convertedXML,"KEYWORD","hello")
Let $final_output: = fn - bea:inlinedXML ($temp_string)
return $final_output
Now, notice that the xml entry still varies as * < Z > keyword / < z > * or keyword < B > < C > < D >/< d: > < E > keyword < /E > < / c > < / b > or anything, only 'KEYWORD' will be there for you.
Because xml input varies, I don't have a diagram. What if I want to use to replace action by node contained in the variable received_input? I need to calculate the xpath of the node that has the value = KEYWORD. It is a dynamic calculation of xpath.
I wonder if there is a feature of xquery that I could use in OSB for this? Basically idea is to contribute a value and function returns the xpath of the node which conntains the value.
Thanks and greetings
Patricia KharwadkarHi Patricia Kharwadkar,.
You can do what you want using plain xpath...
$input =
b
keyword d keyword $value = "Hello".
Replace the Xpath = / / * [. = 'keyword'] variable = expression of $input = $value (replace content of the node) will give you...
b
hello d hello This works for any schema that the xpath expression is looking for content only.
I hope this helps...
See you soon,.
Vlad -
Reg: Doubt in XQuery FLWOR expression
Hello Experts,
I have a XML like this-
< root >
< Reports >
< report >
< ReportName > ABCM < / ReportName >
. . . other details...
< / report >
< report >
< ReportName > XYZZ < / ReportName >
. . . other details...
< / report >
< report >
< ReportName > ABCXO < / ReportName >
. . . other details...
< / report >
< report >
< ReportName > COMO < / ReportName >
.. .other details...
< / report >
< / Reports >
< / root >
I have try it like this.
Select x1.*
Of
test_xml,
XMLTABLE)
' for $i in Root/reports/reports
where $i / ReportName in ('ABCM', 'ABCXO')
Return $i"
in passing test_xml.dx
columns
slno for the ordinalite,
path of varchar2 (15) report_name 'NomRapport. "
sequence_number number path "SequenceNumber".
) x 1
;
My doubt is in the red part above.
I want to go get the details only for reports whose name start with 'ABC '. Even $i / ReportName as 'ABC%' will raise an error
ORA-19114: XPST0003 - error during parsing of the XQuery expression:
LPX-00801: error of XQuery syntax to "like".
2 where $i / ReportName as 'ABC% '.
- ^
19114 00000 - "error during the analysis of the XQuery expression: %s.
* Cause: An error occurred during parsing of the XQuery expression.
* Action: Check the error message for possible causes.
Error on line: column 2:30
Please notify.
Thank you and best regards,
-Nordine
(on Oracle 11.2.0.3.0)
I gave you example ora: matches. It is easy to change it to use fn:starts - with:
with t as)
Select xmltype (')
xmlDoc ') of doubleABCM 1 XYZZ 2 ABCXO 3 JULIE 4 )
Select x1.*
t,.
XMLTable)
"' / Root/reports/reports [fn:starts - with (ReportName,"ABC")].
passage xmldoc
columns
slno for the ordinalite,
path of varchar2 (15) report_name 'NomRapport. "
sequence_number number path "SequenceNumber".
) x 1
/
SLNO REPORT_NAME SEQUENCE_NUMBER
---------- --------------- ---------------
1 ABCM 1
2 ABCXO 3SQL >
SY.
-
How can I share items using XQuery or XPath values?
Hello
is there a way to do this?
For example
becomes<CD026A> <MesSenMES3>NTA.DE</MesSenMES3> <MesRecMES6>TRD.GR</MesRecMES6> </CD026A>
Thanks in advance for your comments<CD026A> <MesSenMES3>TRD.GR</MesSenMES3> <MesRecMES6>NTA.DE</MesRecMES6> </CD026A>
Best regards
PhilippeNo doubt.
Based on the old account information, I guess
will be a recurring element. So I would build an update (based on the 'position' / 'POSITION for ordinalite', in XPATH position() function via PL/SQL and their update (swap), the and at once so content still would have the same structure, iow 'XXX.) XX. " The content could be replaced and or split via 'SUBSTR' and 'REPLACE '. -
Reg: regular expr doubt-
Hi Experts,
I have a doubt of simple query. A play with regular expressions and assigning independent assignments.
with t as (txt)
(
Select 'my name is Vanessa and a good buoy' from dual UNION ALL
Select "nordine Bolduc" dual UNION ALL
Select 'a' out of two
)
-----------------
Select
txt,
REGEXP_COUNT (txt, '(\w)?', 1, 'i') count_of_chars,-< <-doubt (1)
REGEXP_COUNT (txt,'(\w) + ', 1,' i') count_of_words,.
WW REGEXP_COUNT (txt,'(\w) *', 1, 'i'), - < <-doubt (2)
Length (txt) length_of_string
t;
TXT COUNT_OF_CHARS COUNT_OF_WORDS WW LENGTH_OF_STRING
-------------------------------- -------------- -------------- ---------- ----------------
my name is Vanessa and a good buoy 33 8 16 32
ranit biswas 13 2 4 12
a 2 1 2 1
Doubts:
(1) why is there a mismatch of County between columns 2 and 5 IE count_of_chars and length_of_string?
Difference in number is 1.
This is the beginning (^) or end ($) character, which is counted?
Why 2) (\w)* difffer so to (\w)+ ?))
Am I missing some basic notion? Please notify.
Thank you and best regards,
-Nordine
(on Oracle 11.2.0.3.0 - Exadata)
Hello
nordine B wrote:
...
SQL > select regexp_replace ('faaafbabaffab','([ab]*) ', '<\1>') double val;VAL
-----------------------------
<>f<>f \1><>f<>f <> Here, is: whenever a character does not match with any character in the set match ([ab] here), looks like a character before it?
So, the first character has been verified that is 'f' because it does not, a '<>' was placed before the "f".
What is the internal work?
You will find perhaps clearer to imagine a pointer that can be placed before or after the characters, from before the first character after the last character and to check if the model is on the right.
When the pointer is before the 1st character, there is 0 the or BS on his right, so replace you these 0 characters with '<>' and increments the pointer.
When the pointer is after the 1st character, but before the 2nd character, there are 3 has the right, if you replace these 3 characters with '
, and move the pointer to the end of these 3 characters. ...
When the pointer is between 11 and 12 characters, there are 2 a and b to the right, if you replace these 2 characters by '
' and move the position of the pointer 2 to the right. When the pointer is after the 13 character (in other words, the last character), there is 0 a or b to his right, so replace you these 0 characters with '<>',
-
Evaluation of a String XPath Expression with the Variable
SQL & gt; Select * from version of v$.
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
PL/SQL Release 11.2.0.2.0 - Production
CORE Production 11.2.0.2.0
AMT for 32-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
5 selected lines.
SQL & gt; Get & xdb.eval
1 xquery
2. let $x: = document {& lt; doc & gt; & lt; a & gt; 1 & lt; /a & gt; & lt; b & gt; 2 & lt; /b & gt; & lt; c & gt; 3 & lt; / c & gt; & lt; / doc & gt ;}}
3. let $i: = ' / doc/one.
4 * return $x (: {$i} :))
SQL & gt; /
Result sequence
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
& lt; doc & gt; & lt; a & gt; 1 & lt; /a & gt; & lt; b & gt; 2 & lt; /b & gt; & lt; c & gt; 3 & lt; / c & gt; & lt; / doc & gt;
1 item (s) selected.
SQL & gt; Edit
A written file afiedt.buf
1 xquery
2. let $x: = document {& lt; doc & gt; & lt; a & gt; 1 & lt; /a & gt; & lt; b & gt; 2 & lt; /b & gt; & lt; c & gt; 3 & lt; / c & gt; & lt; / doc & gt ;}}
3. let $i: = ' / doc/one.
4 * return $x {$i}
SQL & gt; /
ERROR:
ORA-19114: XPST0003 - error during parsing of the XQuery expression:
LPX-00801: XQuery syntax error in ' {'}
3. return $x {$i}
- ^
SQL & gt; -expected result: & lt; a & gt; 1 & lt; /a & gt;
My goal is to use the results of the xmldiff function to analyze the changes in xml documents. The xmldiff product update-nodes with xpath attribute elements. I want to produce a result extended with surrounding elements of the node has changed. This feature to evaluate the content of a variable in UNIX is provided by the $(expr) or the function eval in other script languages. How this is done in xquery?
Edited by: 880283 August 18, 2011 19:26Hello
There is no standard XQuery function to do.
Here are some alternatives:
1 - construction of the entire XQuery expression dynamically
2. using a user-defined function to access the items dealt with by the XPath expression
3 - use excerpt function, but it is obsolete...Example 1-
SQL> var doc1 varchar2(4000) SQL> var doc2 varchar2(4000) SQL> begin 2 3 :doc1 := '
4 '; 9 10 :doc2 := '- 5
8ABC 6XYZ 711 '; 19 20 end; 21 / PL/SQL procedure successfully completed SQL> with t as ( 2 select xmldiff(xmltype(:doc1), xmltype(:doc2)) xdiff_doc 3 from dual 4 ) 5 select x.*, 6 xmlserialize(document 7 xmlquery(x.parent_xpath 8 passing xmltype(:doc1) 9 returning content 10 ) 11 as clob indent 12 ) parent_node 13 from t, 14 xmltable( 15 xmlnamespaces('http://xmlns.oracle.com/xdb/xdiff.xsd' as "xd"), 16 '/xd:xdiff/child::*' 17 passing t.xdiff_doc 18 columns 19 op_type varchar2(30) path 'local-name(.)' 20 , node_type varchar2(30) path '@xd:node-type' 21 , parent_xpath varchar2(2000) path '@xd:parent-xpath' 22 , attribute_name varchar2(30) path '@xd:attr-local' 23 ) x 24 ; OP_TYPE NODE_TYPE PARENT_XPATH ATTRIBUTE_NAME PARENT_NODE ------------------------------ ------------------------------ ---------------------------- ------------------------------ ---------------------------------- delete-node attribute /root[1]/item[1] id- 12
15ABC 13XYZ 14- 16
18123 17ABC XYZ ABC XYZ Published by: odie_63 on August 19, 2011 10:40
- 5
-
create xmlindex structured with multiple columns reflecting different XPath expressions
I run a XMLEXISTS query to return documents that contain a specific search template. The search model is based on two distinct XPATHS. I tried to create an XML Index structured to support the request. While I can make it work when I specify that a XPATH, I can't make it work when I specify both.
Oracle version: 11.2.0.3
extendeddata / / DESC
Name Null? Type
----------------------------------------- -------- ----------------------------
U NOT NULL VARCHAR2 (14)
XMLCONTENT NOT NULL SYS. XMLTYPE BINARY STORAGE
ROWINSERTDATE NOT NULL DATE
XMLSIZE NOT NULL NUMBER (10)
DATAIMPORTID NOT NULL VARCHAR2 (100)
MESSAGEFLOWNAME NOT NULL VARCHAR2 (200)
Table is partitioned by month on ROWINSERTDATE
XMLType column stored as files secure.
Here's the query...
SELECT u, xmlcontent
To extendeddata
WHERE the XMLEXISTS ('declare namespace CAMT54 = "urn: iso: std: iso: 20022:tech:xsd:camt.054.001.02";)
$p / CAMT54:Document / CAMT54:BkToCstmrDbtCdtNtfctn / CAMT54:Ntfctn [CAMT54:Acct / CAMT54:Id / CAMT54:IBAN = $iban]
[and CAMT54:Ntry / CAMT54:CdtDbtInd = $ctddbtind]' Xmlcontent passing that 'p ',.
"XXXXXXXXXXXXXXXXXXXXXX" AS "iban",.
"DBIT" as "ctddbtind")
AND rowinsertdate > = TO_DATE (' 2014-06-01 00:00:00 ',' ' SYYYY-MM-DD HH24:MI:SS)
AND rowinsertdate < TO_DATE (' 2014-07-01 00:00:00 ',' SYYYY-MM-DD HH24:MI:SS');
Here's the index...
CREATE INDEX EXTENDEDDATA_XML_IDX1 ON EXTENDEDDATA (XMLCONTENT)
INDEXTYPE IS XDB. XMLIndex LOCAL SETTINGS (' XMLTable EXTENDEDDATAIBAN)
XMLNAMESPACES ("urn: iso: std: iso: 20022:tech:xsd:camt.054.001.02" as "CAMT54").
"/ CAMT54:Document / CAMT54:BkToCstmrDbtCdtNtfctn / CAMT54:Ntfctn"
COLUMNS
IBAN VARCHAR (34) PATH "CAMT54:Acct / CAMT54:Id / CAMT54:IBAN".
CTDDBTIND varchar (4) PATH "CAMT54:Ntry / CAMT54:CdtDbtInd" ');
CREATE INDEXES SEPA_PAY. EXTENDEDDATAIBAN_IDX1 ON EXTENDEDDATAIBAN (IBAN, CTDDBTIND)
TABLESPACE SEPA_PAY_BIG_IDX;
exec dbms_stats.gather_table_stats (ownname = > 'SEPA_PAY', tabname = > 'EXTENDEDDATA');
Here is the plan to explain it...
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Hash value of plan: 417322092
--------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1050 | 648KO | 38 (0) | 00:00:01 | | |
|* 1 | FILTER | | | | | | | |
| 2. RANGE OF SINGLE PARTITION | | 1050 | 648KO | 32 (0) | 00:00:01 | 16. 16.
| 3. TABLE ACCESS FULL | EXTENDEDDATA | 1050 | 648KO | 32 (0) | 00:00:01 | 16. 16.
| 4. SEMI NESTED LOOPS. | 1. 6. 6 (0). 00:00:01 | | |
| 5. SEMI NESTED LOOPS. | 1. 4. 4 (0) | 00:00:01 | | |
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
| 6. XPATH EVALUATION. | | | | | | |
|* 7 | XPATH EVALUATION. | | | | | | |
|* 8 | XPATH EVALUATION. | | | | | | |
--------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
1 Filter (EXISTS (SELECT / * + < impossible >))
7 - filter("P2"."$ C_01"="DBIT')
8 - filter("P1"."$ C_01"="XXXXXXXXXXXXXXXXXXXXXX')
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Note
-----
-Construction detected no optimized XML (activate XMLOptimizationCheck for more information)
The following is an extract from the XML file...
" < document xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "xmlns =" urn: iso: std: iso: 20022:tech:xsd:camt.054.001.02 "" >
< BkToCstmrDbtCdtNtfctn >
< GrpHdr >
< MsgId > NFTTEST201311060150412 < / MsgId >
< CreDtTm > 2013 - 11 - 06T 15: 04:12 < / CreDtTm >
< / GrpHdr >
< Ntfctn >
< id > 00001 / < ID >
< CreDtTm > 2013 - 11 - 06T 15: 04:12 < / CreDtTm >
< Acct >
< id >
XXXXXXXXXXXXXXXXXXXXXX < IBAN > < / IBAN >
< /ID >
< / Acct >
< do >
< Amt CTL = "EUR" > 89.00 < / Amt >
< CdtDbtInd > DBIT < / CdtDbtInd >
< m > BOOK < / m >
< BkTxCd >
< Prtry >
< Cd > 99999999999999 < CD >
< / Prtry >
< / BkTxCd >
< NtryDtls >
< TxDtls >
< refs >
< Course > 999_99999999 < / course >
< MndtId > str1234 < / MndtId >
< / refs >
< AmtDtls >
< TxAmt >
< Amt CTL = "EUR" > 89.00 < / Amt >
< / TxAmt >
< / AmtDtls >
< BkTxCd >
< Domn >
< Cd > < CD > SEPA
< Montaut >
< Cd > < CD > SEPA
< SubFmlyCd > CORE < / SubFmlyCd >
< / Montaut >
< / Domn >
< / BkTxCd >
< RltdPties >
< UltmtDbtr >
str1234 < n > < /Nm >
< id >
< OrgId >
< BICOrBEI > XXXXXXXX < / BICOrBEI >
< Scout >
str1234 < id > < /ID >
< SchmeNm >
str1 < Cd > < CD >
< / SchmeNm >
str1234 < HIRS > < / HIRS >
< / Scout >
< / OrgId >
< /ID >
< / UltmtDbtr >
< Instantane >
str1234 < n > < /Nm >
< PstlAdr >
< Ctry > IE < / Ctry >
< AdrLine > str1234 < / AdrLine >
< / PstlAdr >
< / Instantane >
< CdtrAcct >
< id >
XXXXXXXXXXXXXXXXXXXXXX < IBAN > < / IBAN >
< /ID >
< CTL > EUR < / CTL >
< / CdtrAcct >
< UltmtCdtr >
str1234 < n > < /Nm >
< id >
< OrgId >
< BICOrBEI > XXXXXXXX < / BICOrBEI >
< Scout >
str1234 < id > < /ID >
< SchmeNm >
str1 < Cd > < CD >
< / SchmeNm >
str1234 < HIRS > < / HIRS >
< / Scout >
< / OrgId >
< /ID >
< / UltmtCdtr >
< Prtry >
< Tp > default SEPA < /TP >
< Pty >
< id >
< PrvtId >
< Scout >
< id > < /ID > XXXXXXXXXXXXX
< / Scout >
< / PrvtId >
< /ID >
< / Pty >
< / Prtry >
< / RltdPties >
< Purp >
str1 < Cd > < CD >
< / Purp >
< RmtInf >
< Ustrd > str1234 < / Ustrd >
< Strd >
< CdtrRefInf >
< Tp >
< CdOrPrtry >
< Cd > SCOR < CD >
< / CdOrPrtry >
str1234 < HIRS > < / HIRS >
< /TP >
< ref > str1234 < / Ref >
< / CdtrRefInf >
< / Strd >
< / RmtInf >
< / TxDtls >
< / NtryDtls >
< / try >
< / Ntfctn >
< / BkToCstmrDbtCdtNtfctn >
< / document >
Can someone help me build an index for the query above?
Thank you.
This should work better, with the caveat explained above:
SELECT t.* FROM extendeddata t WHERE XMLEXISTS('declare default element namespace "urn:iso:std:iso:20022:tech:xsd:camt.054.001.02";(::) /Document/BkToCstmrDbtCdtNtfctn/Ntfctn[Acct/Id/IBAN=$iban]' Passing Xmlcontent, 'XXXXXXXXXXXXXXXXXXXXXX' AS "iban" ) and XMLEXISTS('declare default element namespace "urn:iso:std:iso:20022:tech:xsd:camt.054.001.02";(::) /Document/BkToCstmrDbtCdtNtfctn/Ntfctn[Ntry/CdtDbtInd=$ctddbtind]' Passing Xmlcontent, 'DBIT' as "ctddbtind") AND rowinsertdate >= TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') AND rowinsertdate < TO_DATE(' 2014-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') ;
(see how the predicates in each XQuery expression corresponds to the structure of the index)
BTW, this kind of "DIY" XMLEXISTS works just as well.
It emulates what we would have hoped for a single XMLExists in the first place:
SQL> SELECT t.* 2 FROM extendeddata t 3 WHERE rowinsertdate >= TO_DATE(' 2015-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') 4 AND rowinsertdate < TO_DATE(' 2015-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') 5 AND EXISTS ( 6 SELECT null 7 FROM XMLTable( 8 XMLNamespaces(default 'urn:iso:std:iso:20022:tech:xsd:camt.054.001.02') 9 , '/Document/BkToCstmrDbtCdtNtfctn/Ntfctn' 10 passing t.xmlcontent 11 COLUMNS IBAN VARCHAR2(34) PATH 'Acct/Id/IBAN' 12 , CTDDBTIND VARCHAR2(4) PATH 'Ntry/CdtDbtInd' 13 ) x 14 WHERE x.iban = 'XXXXXXXXXXXXXXXXXXXXXX' 15 AND x.ctddbtind = 'DBIT' 16 ) ; Execution Plan ---------------------------------------------------------- Plan hash value: 409033022 --------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 824 | 4 (25)| 00:00:01 | | 1 | NESTED LOOPS | | 1 | 824 | 4 (25)| 00:00:01 | | 2 | SORT UNIQUE | | 1 | 38 | 2 (0)| 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID BATCHED| EXTENDEDDATAIBAN | 1 | 38 | 2 (0)| 00:00:01 | |* 4 | INDEX RANGE SCAN | EXTENDEDDATAIBAN_IDX1 | 1 | | 1 (0)| 00:00:01 | |* 5 | TABLE ACCESS BY USER ROWID | EXTENDEDDATA | 1 | 786 | 1 (0)| 00:00:01 | --------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - access("SYS_SXI_1"."IBAN"='XXXXXXXXXXXXXXXXXXXXXX' AND "SYS_SXI_1"."CTDDBTIND"='DBIT') 5 - filter("ROWINSERTDATE">=TO_DATE(' 2015-06-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ROWINSERTDATE"
-
XPath to capture nodes between two nodes
Hi all
I met a problem a seemingly simple challenge of mine.
I have the following xml code.
Basically, I would like to capture the text between the begin-end blocks
<? XML version = "1.0" encoding = "UTF-8"? >
< document >
< body >
< paragraph >
< run >
< fld type = 'start' / >
< / run >
< run >
< text > SAMPLE < / text >
< / run >
< run >
< text > < / text >
< / run >
< run >
< text > FIELD < / text >
< / run >
< run >
< fld type = 'end' / >
< / run >
< run >
< text > TEXT UNWANTED SOME < / text >
< / run >
< / paragraph >
< paragraph >
< run >
< fld type = 'start' / >
< / run >
< run >
< text > SAMPLE < / text >
< / run >
< run >
< text > < / text >
< / run >
< run >
< text > Field2 < / text >
< / run >
< run >
< fld type = 'end' / >
< / run >
< run >
< text > TEXT UNWANTED SOME < / text >
< / run >
< run >
< fld type = 'start' / >
< / run >
< run >
< text > SAMPLE < / text >
< / run >
< run >
< text > < / text >
< / run >
< run >
< text > FIELD3 < / text >
< / run >
< run >
< fld type = 'end' / >
< / run >
< / paragraph >
< / body >
< / document >
So far, what I came up with is:
WITH temp AS ( SELECT XMLTYPE ('<?xml version="1.0" encoding="UTF-8"?> <document> <body> <paragraph> <run> <fld type="begin" /> </run> <run> <text>SAMPLE</text> </run> <run> <text> </text> </run> <run> <text>FIELD</text> </run> <run> <fld type="end" /> </run> <run> <text>SOME UNWANTED TEXT</text> </run> </paragraph> <paragraph> <run> <fld type="begin" /> </run> <run> <text>SAMPLE</text> </run> <run> <text> </text> </run> <run> <text>FIELD2</text> </run> <run> <fld type="end" /> </run> <run> <text>SOME UNWANTED TEXT</text> </run> <run> <fld type="begin" /> </run> <run> <text>SAMPLE</text> </run> <run> <text> </text> </run> <run> <text>FIELD3</text> </run> <run> <fld type="end" /> </run> </paragraph> </body> </document>') AS xml_template FROM dual ) SELECT x.* FROM temp ,XMLTABLE('//*/paragraph/run[fld/@type="begin"]/following-sibling::run[following-sibling::run[fld/@type="end"]]/text' PASSING temp.xml_template COLUMNS res varchar2(100) PATH '.' )x
Result:
RES
SAMPLE
FIELD
SAMPLE
FIELD2
SOME UNWANTED TEXT
SAMPLE
FIELD3
Unfortunately what I wrote XPath is not good enough, because with regard to the text between the two blocs of start-end it still captures the unwanted text.
My XPath knowledgege dept unfortunately not so I would appriciate annything you can help me with even an idea could get through on the edge.
Thank you
Steve
Steve,
XQuery can help in this case:
SELECT x.* FROM temp , XMLTABLE('for $begin in /document/body/paragraph/run[fld/@type="begin"] let $end := $begin/following-sibling::run[fld/@type="end"][1] return $begin/following-sibling::run[. << $end]' PASSING temp.xml_template COLUMNS res varchar2(100) PATH 'text' ) x ;
Explanation:
This FLWOR expression traverses all nodes 'start' in the document, finds the corresponding node of the 'end' and returns the sequence of "run" nodes follows 'begin' and above 'end '.
If you want to concatenate all the fragments of text in a block, you can also do it directly, like this:
for $begin in /document/body/paragraph/run[fld/@type="begin"] let $end := $begin/following-sibling::run[fld/@type="end"][1] return string-join($begin/following-sibling::run[. << $end]/text, "")
She's going back 3 ranks:
RES
-------------
EXAMPLE OF A FIELD
SAMPLE FIELD2
SAMPLE FIELD3
Maybe you are looking for
-
Issue of recovery with Satellite L755 - 12G - blue screen at startup
Hello, my name is Johann and I'm from the Germany (sorry for my bad English, I hope you understand) I have a TOSHIBA Type: * Satellite L755 - 12 G *.REF.: * PSK2YE-03E015GRSerial number: * 7B144840W *. My problem is that I have a blue screen before I
-
I have a hp430 laptop with Windows 7 64 bit ultimate. After having a kind of pilot/virus that froze my computer, even once, I reinstalled my laptop with windows 7 64-bit ultimate. Now it cannot connect to the internet through wireless. I tried all th
-
Solitare opens suddenly, with cards staked in a stack to the top left corner. I was not able to detach them to play a game. Help!
-
Cannot remove the battery? E1 572
How on Earth to remove the battery of an E1 Aspire 572? I don't see any release on the laptop at all and tried to find a way without success throughout the day. What I saw through the box, before he came, but there is no manual as a guide on how to I
-
Original title: keep displaying "Yahoo! Toolbar" add-on "Yahoo", Inc. is ready to use. DO NOT TURN ON. I continue to select ACTIVATE do not, but guest continues to appear. Keep reading "Yahoo! Toolbar" add-on "Yahoo", Inc. is ready to use. DO NO