Precompiled xquery functions
I'm trying to find the way to prepare and reuse queries thought the life of application.
I have a bunch of functions that call each other; all of them accept one string parameter and will be called frequently.
What I'm doing is:
1. Prepare following query for each function call (declarations of all and call of one of them):
declare function pg:fun1 ( $t as xs:string )
return "some_node"
declare function pg:fun2 ( $t as xs:string )
return ns:fun1 ( $local_var )
declare variable $p as xs:string external;
return ns:fun1 ( $p )
2. Call function this way:
self.__qe [ function ].setVariableValue ( "p", XmlValue ( XmlValue.STRING, str ( arg ) ) )
return self.__qe [ function ].execute ( self.__dc.qc )
If it would work that would serve my needs, but preparing (step 1) falls with error:
_dbxml.XmlQueryParserError: (6, "Error: Unrecognized character 'p' (0x70) [err:XPST0003], <query>:26:9")
that error on actual function call "return ns:fun1 ( $p )", so it's not sufficient to just declare external variable before query preparation
Maybe I'm taking completely wrong approach, but I couldn't find any tips on how to do that proper way. If somebody can tell me how to prepare bunch of functions and than just call them passing different parameter values, I would be much appreciated.
Hi Philippe,
You would be doing things in a correct manner if you were using XQuery syntax in your query. After unmangling what I think you mean from what you posted, you might want to try something like this:
declare function local:fun1 ( $t as xs:string )
"some_node"
declare function local:fun2 ( $t as xs:string )
local:fun1 ( $t )
declare variable $p as xs:string external;
local:fun1 ( $p )John
Similar Messages
-
User defined xquery function with index enabled
If I use user defined xquery function, can the index be applied within the function?
trados.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by () -->
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:tns="http://ecoit.hp.com/ecg/repository/trados" targetNamespace="http://ecoit.hp.com/ecg/repository/trados" elementFormDefault="qualified">
<complexType name="entry">
<sequence>
<element name="base" type="string"/>
<element name="translation" maxOccurs="unbounded">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="lang"/>
</extension>
</simpleContent>
</complexType>
</element>
</sequence>
<attribute name="xpath" type="string" use="required" xdb:SQLName="XPATH"/>
<attribute name="locator" type="string" use="required"/>
</complexType>
<simpleType name="languages">
<list itemType="string"/>
</simpleType>
<element name="trados" xdb:defaultTable="ECG_REP_TRADOS_TAB" xdb:tableProps="VARRAY XMLDATA.ENTRY STORE AS TABLE ECG_REP_TRADOS_ENTRY_TAB ((PRIMARY KEY (NESTED_TABLE_ID, SYS_NC_ARRAY_INDEX$)) ORGANIZATION INDEX OVERFLOW)">
<complexType>
<sequence>
<element name="entry" type="tns:entry" minOccurs="0" maxOccurs="unbounded" xdb:SQLName="ENTRY"/>
</sequence>
<attribute name="cid" type="string"/>
<attribute name="path" type="string"/>
<attribute name="lang" type="string"/>
<attribute name="langs" type="tns:languages"/>
<attribute name="oldversion" type="string"/>
</complexType>
</element>
</schema>
CREATE INDEX ECG_REP_ENTRY_XPATH_IDX ON ECG_REP_TRADOS_ENTRY_TAB ("XPATH", "NESTED_TABLE_ID")
eco_category.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by Jan-Erik Pedersen (HEWLETT PACKARD) -->
<!--W3C Schema generated by XMLSpy v2007 (http://www.altova.com) by Scott Dismukes (Hewlett Packard)-->
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:tns="http://ecoit.hp.com/ecg/repository/eco/category" xmlns:cns="http://ecoit.hp.com/ecg/repository/types" targetNamespace="http://ecoit.hp.com/ecg/repository/eco/category" elementFormDefault="qualified">
<import namespace="http://ecoit.hp.com/ecg/repository/types" schemaLocation="../types.xsd"/>
<complexType name="productFamilies">
<sequence>
<element name="productFamily" type="tns:productFamily" minOccurs="0" maxOccurs="unbounded"/>
<element name="product" type="tns:product" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="lang" use="required" xdb:SQLName="LANG">
<simpleType>
<restriction base="string">
<length value="5"/>
</restriction>
</simpleType>
</attribute>
<attribute name="version" use="required" xdb:SQLName="VERSION">
<simpleType>
<restriction base="string">
<maxLength value="100"/>
</restriction>
</simpleType>
</attribute>
</complexType>
<complexType name="productCategory">
<sequence>
<element name="label" type="cns:label"/>
<element name="productCategory" type="tns:productCategory" minOccurs="0" maxOccurs="unbounded" xdb:defaultTable="ECG_REP_ECO_CATALOG_PC_TAB"/>
<element name="product" type="tns:product" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="cns:id" use="required"/>
</complexType>
<complexType name="productCategories">
<sequence>
<element name="productCategory" type="tns:productCategory" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="column">
<sequence>
<element name="label" type="cns:label"/>
</sequence>
<attribute name="id" type="cns:id" use="required"/>
</complexType>
<complexType name="product">
<sequence>
<element name="label" type="cns:label"/>
<element name="column" type="tns:column" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="cns:id" use="required"/>
</complexType>
<complexType name="productFamily">
<sequence>
<element name="label" type="cns:label"/>
<element name="image" type="cns:image" minOccurs="0" maxOccurs="unbounded"/>
<element name="link" type="cns:link" minOccurs="0" maxOccurs="unbounded"/>
<element name="column" type="tns:column" minOccurs="0" maxOccurs="unbounded"/>
<element name="productCategories" type="tns:productCategories" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="cns:id" use="required"/>
</complexType>
<element name="productFamilies" type="tns:productFamilies" xdb:defaultTable="ECG_REP_ECO_CATALOG_TAB"/>
</schema>
xquery
xquery version "1.0";
declare namespace typ = "http://ecoit.hp.com/ecg/repository/types";
declare namespace c = "http://ecoit.hp.com/ecg/repository/eco/category";
declare namespace t = "http://ecoit.hp.com/ecg/repository/trados";
declare variable $c := $res/c:productFamilies;
declare function local:pc($pc as element(c:productCategory), $x as xs:string) as element()
<c:productCategory id="{$pc/@id}">
<c:label>{data($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
for $p in $pc/c:product
return local:p($p, concat($x, "/product/[@id=", $p/@id, "]"))
for $pcc in $pc/c:productCategory
return local:pc($pcc, concat($x, "/productCategory[@id=", $pcc/@id, "]"))
</c:productCategory>
declare function local:p($p as element(c:product), $x as xs:string) as element()
<c:product id="{$p/@id}">
<c:label>{string($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
for $col in $p/c:column
return
<c:column id="{$col/@id}">
<c:label>
let $e := $es/t:entry[@xpath eq concat($x, "/column[@id=", $col/@id, "]/label")]
return
if(exists($e)) then string($e/t:translation)
else $col/c:label/text()
</c:label>
</c:column>
</c:product>
<c:productFamiles xsi:schemaLocation="http://ecoit.hp.com/ecg/repository/eco/category http://ecoit.hp.com/ecg/repository/eco/category.xsd http://ecoit.hp.com/ecg/repository/types http://ecoit.hp.com/ecg/repository/types.xsd" lang="{$lang/lang/text()}" version="{$c/@version}">
for $pf in $c/c:productFamily
let $x := concat("/productFamily[@id=", $pf/@id, "]")
return
<c:productFamily id="{$pf/@id}">
(:xpath index can not be applied within function:)
<c:label>{data($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
for $img in $pf/c:image
return $img
for $link in $pf/c:link
return $link
for $col in $pf/c:column
return
<c:column id="{$col/@id}">
<c:label>{data($es/t:entry[@xpath eq concat($x, "/column[@id=", $col/@id, "]/label")]/t:translation)}</c:label>
</c:column>
for $pcs in $pf/c:productCategories
return
<c:productCategories>
for $pc in $pcs/c:productCategory
return local:pc($pc, concat($x, "/productCategories/productCategory[@id=", $pc/@id, "]"))
</c:productCategories>
</c:productFamily>
for $p in $c/c:product
return local:p($p, concat("/product[@id=", $p/@id, "]"))
</c:productFamiles>
Message was edited by:
John LeeJohn
Am i missing a bit of the Xquery
In 11.1,0.6.0 I get
Elapsed: 00:00:00.04
SQL> set echo on
SQL> spool testcase.log
SQL> --
SQL> connect sys/ as sysdba
Enter password:
Connected.
SQL> set define on
SQL> set timing on
SQL> --
SQL> define USERNAME = HPECO
SQL> --
SQL> def PASSWORD = HPECO
SQL> --
SQL> def USER_TABLESPACE = USERS
SQL> --
SQL> def TEMP_TABLESPACE = TEMP
SQL> --
SQL> drop user &USERNAME cascade
2 /
old 1: drop user &USERNAME cascade
new 1: drop user HPECO cascade
User dropped.
Elapsed: 00:00:18.12
SQL> grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASSW
ORD
2 /
old 1: grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &P
ASSWORD
new 1: grant create any directory, drop any directory, connect, resource, alter session, create view to HPECO identified by HPECO
Grant succeeded.
Elapsed: 00:00:00.03
SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
2 /
old 1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
new 1: alter user HPECO default tablespace USERS temporary tablespace TEMP
User altered.
Elapsed: 00:00:00.00
SQL> connect &USERNAME/&PASSWORD
Connected.
SQL> --
SQL> alter session set events ='19027 trace name context forever, level 0x800'
2 /
Session altered.
Elapsed: 00:00:00.00
SQL> --
SQL> declare
2 xmlschema xmltype := XMLTYPE(
3 '<?xml version="1.0" encoding="UTF-8"?>
4 <!-- edited with XMLSpy v2008 (http://www.altova.com) by Jan-Erik Pedersen (HEWLETT PACKARD) -->
5 <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:tns="http://ecoit.hp.com/ecg/rep
ository/types" targetNamespace="http://ecoit.hp.com/ecg/repository/types" elementFormDefault="qualified">
6 <complexType name="item">
7 <simpleContent>
8 <extension base="tns:content">
9 <attribute name="id" type="tns:id" use="required"/>
10 </extension>
11 </simpleContent>
12 </complexType>
13 <complexType name="items">
14 <sequence>
15 <element name="item" type="tns:item" maxOccurs="unbounded"/>
16 </sequence>
17 <attribute name="id" type="tns:id" use="required"/>
18 </complexType>
19 <complexType name="mappings">
20 <sequence>
21 <element name="item" type="tns:item" minOccurs="0" maxOccurs="unbounded"/>
22 <element name="items" type="tns:items" minOccurs="0" maxOccurs="unbounded"/>
23 </sequence>
24 </complexType>
25 <complexType name="local">
26 <sequence>
27 <element name="common">
28 <complexType>
29 <sequence>
30 <element name="texts" type="tns:mappings"/>
31 <element name="images" type="tns:mappings" minOccurs="0"/>
32 </sequence>
33 </complexType>
34 </element>
35 <element name="section" minOccurs="0" maxOccurs="unbounded">
36 <complexType>
37 <sequence>
38 <element name="texts" type="tns:mappings"/>
39 <element name="images" type="tns:mappings" minOccurs="0"/>
40 </sequence>
41 <attribute name="id" use="required">
42 <simpleType>
43 <restriction base="string">
44 <maxLength value="32"/>
45 </restriction>
46 </simpleType>
47 </attribute>
48 </complexType>
49 </element>
50 </sequence>
51 <attribute name="lang" use="required" xdb:SQLName="LANG">
52 <simpleType>
53 <restriction base="string">
54 <length value="5"/>
55 </restriction>
56 </simpleType>
57 </attribute>
58 </complexType>
59 <complexType name="link">
60 <sequence>
61 <element name="url" type="tns:url"/>
62 <element name="label" type="tns:label"/>
63 <element name="image" type="tns:image" minOccurs="0"/>
64 </sequence>
65 <attribute name="id" type="tns:id"/>
66 </complexType>
67 <complexType name="image">
68 <sequence>
69 <element name="url" type="string"/>
70 <element name="label" type="tns:label" minOccurs="0"/>
71 </sequence>
72 <attribute name="id" type="tns:id" use="optional"/>
73 </complexType>
74 <simpleType name="id">
75 <restriction base="string">
76 <maxLength value="100"/>
77 </restriction>
78 </simpleType>
79 <simpleType name="label">
80 <restriction base="string">
81 <maxLength value="200"/>
82 </restriction>
83 </simpleType>
84 <simpleType name="content">
85 <restriction base="string">
86 <maxLength value="4000"/>
87 </restriction>
88 </simpleType>
89 <simpleType name="url">
90 <restriction base="string">
91 <maxLength value="256"/>
92 </restriction>
93 </simpleType>
94 </schema>');
95 begin
96 dbms_xmlschema.registerSchema
97 (
98 schemaurl => 'http://ecoit.hp.com/ecg/repository/types.xsd'
99 ,schemadoc => xmlschema
100 ,local => TRUE
101 ,genBean => false
102 ,genTypes => TRUE
103 ,genTables => TRUE
104 ,ENABLEHIERARCHY => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
105 );
106 end;
107 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.35
SQL>
SQL> declare
2 xmlschema xmltype := XMLTYPE(
3 '<?xml version="1.0" encoding="UTF-8"?>
4 <!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by () -->
5 <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:tns="http://ecoit.hp.com/ecg/rep
ository/trados" targetNamespace="http://ecoit.hp.com/ecg/repository/trados" elementFormDefault="qualified">
6 <complexType name="entry">
7 <sequence>
8 <element name="base" type="string"/>
9 <element name="translation" maxOccurs="unbounded">
10 <complexType>
11 <simpleContent>
12 <extension base="string">
13 <attribute name="lang"/>
14 </extension>
15 </simpleContent>
16 </complexType>
17 </element>
18 </sequence>
19 <attribute name="xpath" type="string" use="required" xdb:SQLName="XPATH"/>
20 <attribute name="locator" type="string" use="required"/>
21 </complexType>
22 <simpleType name="languages">
23 <list itemType="string"/>
24 </simpleType>
25 <element name="trados" xdb:defaultTable="ECG_REP_TRADOS_TAB" xdb:tableProps="VARRAY XMLDATA.ENTRY STORE AS TABLE ECG_REP_TRA
DOS_ENTRY_TAB ((PRIMARY KEY (NESTED_TABLE_ID, SYS_NC_ARRAY_INDEX$)) ORGANIZATION INDEX OVERFLOW)">
26 <complexType>
27 <sequence>
28 <element name="entry" type="tns:entry" minOccurs="0" maxOccurs="unbounded" xdb:SQLName="ENTRY"/>
29 </sequence>
30 <attribute name="cid" type="string"/>
31 <attribute name="path" type="string"/>
32 <attribute name="lang" type="string"/>
33 <attribute name="langs" type="tns:languages"/>
34 <attribute name="oldversion" type="string"/>
35 </complexType>
36 </element>
37 </schema>');
38 begin
39 dbms_xmlschema.registerSchema
40 (
41 schemaurl => 'http://ecoit.hp.com/ecg/repository/trados.xsd'
42 ,schemadoc => xmlschema
43 ,local => TRUE
44 ,genBean => false
45 ,genTypes => TRUE
46 ,genTables => TRUE
47 ,ENABLEHIERARCHY => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
48 );
49 end;
50 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.68
SQL> declare
2 xmlschema xmltype := XMLTYPE(
3 '<?xml version="1.0" encoding="UTF-8"?>
4 <!-- edited with XMLSpy v2008 (http://www.altova.com) by Jan-Erik Pedersen (HEWLETT PACKARD) -->
5 <!--W3C Schema generated by XMLSpy v2007 (http://www.altova.com) by Scott Dismukes (Hewlett Packard)-->
6 <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:tns="http://ecoit.hp.com/ecg/rep
ository/eco/category" xmlns:cns="http://ecoit.hp.com/ecg/repository/types" targetNamespace="http://ecoit.hp.com/ecg/repository/eco/c
ategory" elementFormDefault="qualified">
7 <import namespace="http://ecoit.hp.com/ecg/repository/types" schemaLocation="http://ecoit.hp.com/ecg/repository/types.xsd"/>
8 <complexType name="productFamilies">
9 <sequence>
10 <element name="productFamily" type="tns:productFamily" minOccurs="0" maxOccurs="unbounded"/>
11 <element name="product" type="tns:product" minOccurs="0" maxOccurs="unbounded"/>
12 </sequence>
13 <attribute name="lang" use="required" xdb:SQLName="LANG">
14 <simpleType>
15 <restriction base="string">
16 <length value="5"/>
17 </restriction>
18 </simpleType>
19 </attribute>
20 <attribute name="version" use="required" xdb:SQLName="VERSION">
21 <simpleType>
22 <restriction base="string">
23 <maxLength value="100"/>
24 </restriction>
25 </simpleType>
26 </attribute>
27 </complexType>
28 <complexType name="productCategory">
29 <sequence>
30 <element name="label" type="cns:label"/>
31 <element name="productCategory" type="tns:productCategory" minOccurs="0" maxOccurs="unbounded" xdb:defaultTa
ble="ECG_REP_ECO_CATALOG_PC_TAB"/>
32 <element name="product" type="tns:product" minOccurs="0" maxOccurs="unbounded"/>
33 </sequence>
34 <attribute name="id" type="cns:id" use="required"/>
35 </complexType>
36 <complexType name="productCategories">
37 <sequence>
38 <element name="productCategory" type="tns:productCategory" minOccurs="0" maxOccurs="unbounded"/>
39 </sequence>
40 </complexType>
41 <complexType name="column">
42 <sequence>
43 <element name="label" type="cns:label"/>
44 </sequence>
45 <attribute name="id" type="cns:id" use="required"/>
46 </complexType>
47 <complexType name="product">
48 <sequence>
49 <element name="label" type="cns:label"/>
50 <element name="column" type="tns:column" minOccurs="0" maxOccurs="unbounded"/>
51 </sequence>
52 <attribute name="id" type="cns:id" use="required"/>
53 </complexType>
54 <complexType name="productFamily">
55 <sequence>
56 <element name="label" type="cns:label"/>
57 <element name="image" type="cns:image" minOccurs="0" maxOccurs="unbounded"/>
58 <element name="link" type="cns:link" minOccurs="0" maxOccurs="unbounded"/>
59 <element name="column" type="tns:column" minOccurs="0" maxOccurs="unbounded"/>
60 <element name="productCategories" type="tns:productCategories" minOccurs="0" maxOccurs="unbounded"/>
61 </sequence>
62 <attribute name="id" type="cns:id" use="required"/>
63 </complexType>
64 <element name="productFamilies" type="tns:productFamilies" xdb:defaultTable="ECG_REP_ECO_CATALOG_TAB"/>
65 </schema>
66 ');
67 begin
68 dbms_xmlschema.registerSchema
69 (
70 schemaurl => 'http://ecoit.hp.com/ecg/repository/eco/category.xsd'
71 ,schemadoc => xmlschema
72 ,local => TRUE
73 ,genBean => false
74 ,genTypes => TRUE
75 ,genTables => TRUE
76 ,ENABLEHIERARCHY => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
77 );
78 end;
79 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.65
SQL> CREATE INDEX ECG_REP_ENTRY_XPATH_IDX ON ECG_REP_TRADOS_ENTRY_TAB ("XPATH", "NESTED_TABLE_ID")
2 /
Index created.
Elapsed: 00:00:00.01
SQL> set pages 0 lines 160
SQL> set long 10000
SQL> --
SQL> set autotrace on explain
SQL> --
SQL> xquery
2 xquery version "1.0";
3
4 declare namespace typ = "http://ecoit.hp.com/ecg/repository/types";
5 declare namespace c = "http://ecoit.hp.com/ecg/repository/eco/category";
6 declare namespace t = "http://ecoit.hp.com/ecg/repository/trados";
7
8 declare variable $c := $res/c:productFamilies;
9
10 declare function local:pc($pc as element(c:productCategory), $x as xs:string) as element() {
11 <c:productCategory id="{$pc/@id}">
12 {
13 <c:label>{data($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
14 ,
15 for $p in $pc/c:product
16 return local:p($p, concat($x, "/product/[@id=", $p/@id, "]"))
17 ,
18 for $pcc in $pc/c:productCategory
19 return local:pc($pcc, concat($x, "/productCategory[@id=", $pcc/@id, "]"))
20 }
21 </c:productCategory>
22 };
23
24 declare function local:p($p as element(c:product), $x as xs:string) as element() {
25 <c:product id="{$p/@id}">
26 {
27 <c:label>{string($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
28 ,
29 for $col in $p/c:column
30 return
31 <c:column id="{$col/@id}">
32 <c:label>
33 {
34 let $e := $es/t:entry[@xpath eq concat($x, "/column[@id=", $col/@id, "]/label")]
35 return
36 if(exists($e)) then string($e/t:translation)
37 else $col/c:label/text()
38 }
39 </c:label>
40 </c:column>
41 }
42 </c:product>
43 };
44
45 <c:productFamiles xsi:schemaLocation="http://ecoit.hp.com/ecg/repository/eco/category http://ecoit.hp.com/ecg/repository/eco/ca
tegory.xsd http://ecoit.hp.com/ecg/repository/types http://ecoit.hp.com/ecg/repository/types.xsd" lang="{$lang/lang/text()}" versi
on="{$c/@version}"> {
46 for $pf in $c/c:productFamily
47 let $x := concat("/productFamily[@id=", $pf/@id, "]")
48 return
49 <c:productFamily id="{$pf/@id}">
50 {
51 (:xpath index can not be applied within function:)
52 <c:label>{data($es/t:entry[@xpath eq concat($x, "/label")]/t:translation)}</c:label>
53 ,
54 for $img in $pf/c:image
55 return $img
56 ,
57 for $link in $pf/c:link
58 return $link
59 ,
60 for $col in $pf/c:column
61 return
62 <c:column id="{$col/@id}">
63 <c:label>{data($es/t:entry[@xpath eq concat($x, "/column[@id=", $col/@id, "]/label")]/t:translation)}</c:lab
el>
64 </c:column>
65 ,
66 for $pcs in $pf/c:productCategories
67 return
68 <c:productCategories>
69 {
70 for $pc in $pcs/c:productCategory
71 return local:pc($pc, concat($x, "/productCategories/productCategory[@id=", $pc/@id, "]"))
72 }
73 </c:productCategories>
74 }
75 </c:productFamily>
76 ,
77 for $p in $c/c:product
78 return local:p($p, concat("/product[@id=", $p/@id, "]")) } </c:productFamiles>
79 /
ERROR:
ORA-19228: XPST0008 - undeclared identifier: prefix 'res' local-name ''
Elapsed: 00:00:00.01
SQL> -
Including customized xquery functions in XQuery/XSLT expression Editor-OSB
Hi,
I have written a customized xquery function. I want this to be included in the List of Xquery Functions which is displayed by Oracle Service Bus in the XQuery/XSLT
Expression Editor. OSB displays the built in xquery functions in the XSLT/Xquey Expression Editor. Is there any way to add the customised xquery to this list, so that it can be dragged and dropped later?
Thanks,
Balaji.I doubt if that is exposed out side of Oracle Engineering (Not public/documented). Please raise a support ticket for enhancement. If PM should concur you might get the steps that need to be performed for this feature.
Thanks
Manoj
Edited by: Manoj Neelapu on Jun 8, 2010 8:37 AM -
Hi all.
Is some body know can XQuery functions be used/declared in pl sql? More deep, can I cover XQuery function by pl sql function or procedure? And how to input parameters/variables to Xquery function from pl sql?
Any links to manual will be helpful.
Best regards,
Anton.Something like that?:
SQL> create or replace procedure index_scan (index_name varchar2, name varchar2)
as
xml xmltype;
begin
select xmlquery (
if ("article-by-title" = $index_name) then doc("/wiki")/root/page[title=$name]
else if ("article-by-id" = $index_name) then doc("/wiki")/root/page[id=$name]
else if ("link-by-target" = $index_name) then doc("/wiki")/root/page/links/link[@target = $name]
else if ("article-by-cat" = $index_name) then doc("/wiki")/root/page/catlinks/catlink[@target=$name]
else error(fn:QName("http://www.w3.org/2005/xqt-errors", $index_name) , "Some error occured") '
passing index_name as "index_name", name as "name"
returning content)
into xml
from dual;
end index_scan;
Procedure created.
SQL> exec index_scan('My Index Name','My Name')
BEGIN index_scan('My Index Name','My Name'); END;
Error at line 20
ORA-19112: error raised during evaluation: :My Index Name
Detail: Some error occured
ORA-06512: at "MICHAEL.INDEX_SCAN", line 5
ORA-06512: at line 1Don't have your resources - therefore the error! -
XQuery function : Adding day to current date
I have a requirement to add 1 day to the current date during the Xquery transformation.
Does anyone know if there is any xquery function that does that?
From this link,
http://download.oracle.com/docs/cd/E13214_01/wli/docs92/xref/xqdtopref.html#wp1162860
it seems like there is a function, op: add-yearMonthDuration-to-dateTime, that serve this purpose, but I don't find it in OSB console IDE nor OEPE.You can use the below expression for adding 1 day (24 hrs) to a given current date:
fn:current-dateTime() + xdt:dayTimeDuration("PT24H")
Thanks,
Patrick -
Recursive XQuery functions in transformation
Using WLI 8.1sp2, I am trying to create a recursive XQuery function for use
in a data transformation, but I get the error "unbound function: myFunction"
whenever I try to do something like this:
define function myFunction(element $x)
// do something
myFunction($someVar)
If the recursion is not there, it works fine, but that doesn't work for me
as I need recursion. Also, defining functions like
define function a($x)
b($x)
define function b($x)
$x
does not work either, and I get the same "unbound function" error message.
I thought BEA's XQuery implementation was supposed to be 100% compliant with
the August 2002 spec, which states "A function may be defined
recursively--that is, it may reference its own definition."
(http://www.w3.org/TR/2002/WD-xquery-20020816/#FunctionDefns)
I have also tried adding a namespace qualifier to my function definition as
well, but that doesn't work either. The error I get is "the QName
ns0:myFunction is used instead of an expected NCName."
Has anyone gotten recursive functions working in WLI 8.1sp2?
Thanks in advance,
AndyIs the patch publicly available? I don't see it online at BEA's site.
"bob smith" <[email protected]> wrote in message news:4190ed25$1@mail...
Recursive functions do not work in 8.1sp2. There is a patch;
CR191651
It is fixed in sp4
"Andy Goldstein" <[email protected]> wrote in message
news:4190d370$1@mail...
Using WLI 8.1sp2, I am trying to create a recursive XQuery function foruse
in a data transformation, but I get the error "unbound function:myFunction"
whenever I try to do something like this:
define function myFunction(element $x)
// do something
myFunction($someVar)
If the recursion is not there, it works fine, but that doesn't work for
me
as I need recursion. Also, defining functions like
define function a($x)
b($x)
define function b($x)
$x
does not work either, and I get the same "unbound function" errormessage.
I thought BEA's XQuery implementation was supposed to be 100% compliantwith
the August 2002 spec, which states "A function may be defined
recursively--that is, it may reference its own definition."
(http://www.w3.org/TR/2002/WD-xquery-20020816/#FunctionDefns)
I have also tried adding a namespace qualifier to my function definitionas
well, but that doesn't work either. The error I get is "the QName
ns0:myFunction is used instead of an expected NCName."
Has anyone gotten recursive functions working in WLI 8.1sp2?
Thanks in advance,
Andy -
Documentation for XQuery Functions?
I have been looking for more information on the Aqualogic specific XQuery functions but have so far come up short. In particular I want to know the details for fn-bea:uuid(). I would like to be able to generate a unique identifier to use for correlating messages that come through ALSB in my log. Is there somewhere that I can find a description of what this function does?
WaltK wrote:
Where do I find documentation for APEX provided javascript functions such as addRow();?
addRow is undocumented.
Documented JavaScript methods are described in the API Reference, other documentation for the current version is located on the APEX Documentation page. Documentation for previous versions is located in the documentation archive. -
OSB: Calling XQuery from XQuery function
Hi,
In OSB, is it possible to call XQuery functions from an XQuery. I have a number of XQuery files (.xq) and I want to call them from another xquery file, is that possible. I tried calling directly but it didn't work. Is there a way?
Thank you
MattMatt,
To use custom XPATH/XQuery functions, you need to register them into OSB runtime. Please refer -
http://docs.oracle.com/cd/E21764_01/doc.1111/e15866/custom_xpath.htm#OSBDV1725
http://eelzinga.wordpress.com/2010/05/10/oracle-service-bus-11g-using-custom-xpath-functions/
Regards,
Anuj -
OSB: How to recreate reusable XQuery functions
OSB's XQuery implementation does not support the XQuery "module" which allows the creation of a function library so how can OSB provide function re-use?
I know you can create XQuery transformations that can be called but these always need a "body" that makes a specific call so I'm finiding I have to copy useful XQuery functions from one transformation to another. Ideally I should be able to call an XQuery function external to the transformation.
Does anyone have any pointers on this or is it a fundamental limitation of the OSB XQuery implementation?
regardsWhat we did is creating a seperate project in which we use most of XQuery stuff, using SaxonSA library to run and validate the queries.
This project adds the following possibilities for xqueries:
- Schema validation of XPath used in XQueries (including namespaces)
- XQuery syntax validation (with errors at the exact line and position where it fails.
- Allows the use of modules
- Reqression testing XQueries
Regrettably we can not do Java callout's from XQueries as this is not supported on the ESB.
We also build a simple 'flattener' that takes a module based, schema enriched XQuery and then generates the XQuery that can be used on the ESB itself. The flattened query is also regression tested.
Although it was quite some work to make it, it already has paid back the initial costs of the project in the second or third project we did. We since then have enhanced the project so it also can do regression message flow validation on the OSB (we already had valid input and output messages).
The tool also greatly improves the stability of the code on the OSB, and reduces development time as we can build the XQuery from a unit test environment that will point out typos and other xpath related problems.
We do have some fairly complex xqueries on the OSB, the number of xqueries in the project at the moment is 187 with 250 unittests.
So, if Oracle is not going to include it in the OSB itself (which seems lilkely at the moment), you can build such a system yourself !
Wim Veldhuis,
PharmaPartners BV -
Retrieving Principal Name (=User Id) via XQuery Function
I'm using a custom identity asserter within my WLS to create the security context.
The OSB documentation states, that there is a XQuery function to read the user id from the security context: fn-bea:userid (see XQuery Implementation - 11g Release 1 (11.1.1.7)). Note: I have noticed that Oracle makes a distinction between Function Extensions from Oracle Service Bus and Supported Function Extensions from Oracle a.k.a Oracle’s XQuery Implementation).
When using this XPath function in my OSB installation I receive the following error: {bea-err}SYS001: This functionality has not been implemented (sorry) operator [QName {http://www.bea.com/xquery/xquery-functions}userid]
My questions:
- Is this the correct function to read the user id/user name/principal information from the security context?
- If it is, how can I make that function run in my OSB Domain? Is there a component I need to include/reference?
- If not, what other options do I have? What is best practice? (e.g. Java Callout & accessing the HttpServletRequest object via Java?)
Many thanks in advance.In OSB you can use fn-bea:lookupBasicCredentials($arg-string) function for the same.
Here is the referece: XQuery Implementation - 11g Release 1 (11.1.1.6.3) -
How I can create new XQuery functions in AQSB?
Hi,
I need create XQuery functions in AQSB to use them in proxy services. Is that posible?
Thanks for your help!!! :-)Hi,
Have you activated the IC in the last dialog box of the wizard. Expand the root Account and see if you were able to see your sample BC. If you found that check the box and it will be available in the IC.
Regards,
Joseph -
Passing a node to Xquery function
Hi All,
I have two functions in my xquery. I'm trying to pass a node from one function to another function to check if it exists and do some processing on the text that is present in that node (if exists).
declare function appendLines($node as element()) as xs:string {
if(fn:exists($node) and $node/text() ne "") then
fn:concat($node/text(),", ")
else (
appendLines($LINE_ITEM/ns0:STATXT)
Is the above call to that function is correct?
Thanks!!!declare function appendLines($node as node()*) as xs:string {
if(fn:exists($node)) then
if(fn:string-length(fn:normalize-space($node/text())) > 0) then (
fn:concat($node/text(), " ")
else (
else (
It worked with the above function. -
Including XQuery Functions as part of Tranport Headers in OSB
Hi,
I want to include the current date and time as part of the name of the file generated by a business service.
I tried to use an XQuery Context function which returns current date and time as part of fileName in the transport header (in proxy service).I received a transport error with the code 380001 at run time.
Can you give me an alternate solution ?
Sharanyafn:current-dateTime() returns xs:dateTime type which is in the format YYYY-MM-DDThh:mm:ss+-zz:zz
Because of ':' in the dateTime type you wont be able to set it directly as a filename.
To set the filename to contain date and time reformat the output of fn:current-dateTime() so that it does not contain any ':'.
An example is:
fn:replace(xs:string(fn:current-dateTime()), ':', '.')This gives a string as output in format:
YYYY-MM-DDThh.mm.ss+-zz.zz
Which is a valid filename.
Edited by: AbhishekJ on Jan 3, 2011 12:24 PM -
Error while calling XQuery Function with xs:date type as Argument
Hi,
I have follwing function in my DataService .
declare function tns:getXXXDetail($effectiveDate as xs:date,
$cancelDate as xs:date) as element(ns26:XXXAccount)* {
implCode
declare function tns:testGetXXXDetail($searchCriteria as element(ns15:locateMemberXXXDetail))
as element(ns26:XXXAccount)* {
for $Account in tns:getXXXDetail($searchCriteria/ns16:accountTypeDates/ns18:effectiveDate,
$searchCriteria/ns16:accountTypeDates/ns18:cancelDate)
return $Account
I am trying to test the getXXXDetail() function from testGetXXXDetail .
The searchCriteria is a complex type with date elements effectiveDate and cancelDate, both are optional
When i test with effectiveDate,cancelDate elements present in $searchCriteria its working fine.
When i remove these dates element i am getting follwing error
"expected exactly one item, got 0 items" error
Any Clue ?When i remove these dates element i am getting follwing error"expected exactly one item, got 0 items" error
Sounds like your schema for these items indicates minOccurs="1" (or relies on that as the default).
Edit the schema and change the definitions to be...
<xs:element name="effectiveDate" minOccurs="0" ... /> -
Xquery functions to check values in sequences
Lets say we have an element xyz that occurs 1 or more times inside $body/request. I need to check whether one of its values is "X". Can we do this in XQuery?
I have tried xquery examples given on http://www.xqueryfunctions.com/xq/c0015.html#c0016 but have not been able to get this working. It will be great is someone can illustrate how this can be done.This can be done with basic xQuery and comes down to the difference between '=' and 'eq'.
'=' is an array operator where as 'eq' is for single comparisons.
('x' = ['x','y','z']) -> true
('x' = fn:tokenize('x-y-z', '-') -> true
('x' = \\ns:xyz) -> true
('x' eq \\ns:xyz[1]) -> true
('x' eq \\ns:xyz) -> error if more than 1 xyz!!
Maybe you are looking for
-
I cannot open iPhoto library without upgrading
I think I know the reason: There was recently an upgrade of Aperture, which I have purchased, which asked my to upgrade the iPhoto library. Anyway, iPhoto now says I need to upgrade iPhoto to open my library. And the only upgrade I see has to be paid
-
I am having a frustrating problem with iMovie. I am trying to make a video with sound playing over still images, bu every time i try to extract audio from the video i have, it will not work. It loads, taking 7-12 minutes, and then when i substitute t
-
Unicode string now returned from Stored Proc., used to be ANSI.
Using ADO to connect VB6 to Oracle 8 stored procedures used to return strings in ANSI format. At some point in the last year or so, strings suddenly began to be returned as Unicode, unreadable by VB. Same problem now occurs using VB.Net and ODP.Net;
-
Could anyone tell me how to deduct one cell from another cell in the numbers application. Thank you!
-
Mac Repair in Dakar, Senegal
Community, My Daughter is serving in the Peace Corps in Senegal. She is in need of finding somplace in Dakar, the capital, where she can get her MacBook repaired. Along with her Peace Corps projects, she is in the middle of applying gor grad progra