PL/SQL : User defined Aggregate Functions ??
Is it possible to create (using whatever language) a user defined aggregate function for transparent usage within sql ?
e.g.
select median(myField) from myTable
or
select empirical_expectation(myField) from myTable
thanx in advance ..
Tobias Oberstein
HI,
U can create a stored proc. (PL/SQL) for this and call as any other function.
By using external procedure, U can create shared library in C or C++ and coonect this shared library by using external function/procedure. This will be become user-defined procedure.
with regards,
Boby Jose Thekkanath.
Similar Messages
-
How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCI
Hi
we are using Timesten 11 version and as per the documentation, it doesn't support User-Defined Aggregate Functions.
So we are looking for alternatives to do it. Could you please provide your expert voice on this.
Thanks a lot.
As the following:
create or replace type strcat_type as object (
cat_string varchar2(32767),
static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,
member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,
member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,
member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return
number
How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCIAggregateInitialize ?Dear user6258915,
You absolutely right, TimesTen doesnt support object types (http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e13076/plsqldiffs.htm) and User-Defined Aggregate Functions.
Is it crucial for your application? Could you rewrite this functionality by using standart SQL or PL/SQL?
Best regards,
Gennady -
User-Defined Aggregate Function in oracle
Somebody knows if in oracle 10g is possible to create a User-Defined Aggregate Function?
Sometingh like my_sum, that aggregate the values in a way that i want...
select manager, my_sum(salary)
group by manager
In internet i've found rellay notingh for oracle 10g...can somebody help me? Thank's in advance!Thank's to everybody!!! I've made my custom function sum_distinct
create or replace type AggregateCD as object
( nb number,
ListOfDistinctValue clob,
static function ODCIAggregateInitialize(sctx IN OUT AggregateCD) return number,
member function ODCIAggregateIterate(self IN OUT AggregateCD, value IN VARCHAR2) return number,
member function ODCIAggregateTerminate(self IN AggregateCD, returnValue OUT number, flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT AggregateCD, ctx2 IN AggregateCD) return number
create or replace type body AggregateCD is
static function ODCIAggregateInitialize(sctx IN OUT AggregateCD) return number is
begin
sctx := AggregateCD(0,null);
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT AggregateCD, value IN VARCHAR2) return number is
ListOfValue CLOB:=self.ListOfDistinctValue ;
begin
self.nb:=self.nb+to_number(substr(value , INSTR(value, ';', 1, 1)+1 ,length(value)));
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN AggregateCD, returnValue OUT number, flags IN number) return number is
begin
returnValue := self.nb;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT AggregateCD, ctx2 IN AggregateCD) return number is
begin
self.nb := ctx2.nb;
return ODCIConst.Success;
end;
end;
CREATE OR REPLACE FUNCTION sum_distinct (input VARCHAR2) RETURN number
PARALLEL_ENABLE AGGREGATE USING AggregateCD;you can use so:
select sum_distinct(distinct t.primary_key||';'||t.import)
from table1 t, table2_with_bad_join
it's the same of
select sum(t.import)
from table 1 -
8i personal : error when Create user defined aggregate function
Hi,
I have problem on creating user defined aggregate function.
I try to create the sample aggregate function "SecondMax" from 9i developer guide(append at the end of this post).
It's work to create object type and the type body, but
there is error when I create the aggregate function..
"CREATE FUNCTION SecondMax (input NUMBER) RETURN NUMBER
PARALLEL_ENABLE AGGREGATE USING SecondMaxImpl;"
I am using 8i personal now.. is that the syntax of create function in 9i is different from that in 8i?
Example: Creating and Using a User-Defined Aggregate
This example illustrates creating a simple user-defined aggregate function SecondMax() that returns the second-largest value in a set of numbers.
Creating SecondMax()
Implement the type SecondMaxImpl to contain the ODCIAggregate routines.
create type SecondMaxImpl as object
max NUMBER, -- highest value seen so far
secmax NUMBER, -- second highest value seen so far
static function ODCIAggregateInitialize(sctx IN OUT SecondMaxImpl)
return number,
member function ODCIAggregateIterate(self IN OUT SecondMaxImpl,
value IN number) return number,
member function ODCIAggregateTerminate(self IN SecondMaxImpl,
returnValue OUT number, flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT SecondMaxImpl,
ctx2 IN SecondMaxImpl) return number
Implement the type body for SecondMaxImpl.
create or replace type body SecondMaxImpl is
static function ODCIAggregateInitialize(sctx IN OUT SecondMaxImpl)
return number is
begin
sctx := SecondMaxImpl(0, 0);
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT SecondMaxImpl, value IN number)
return number is
begin
if value > self.max then
self.secmax := self.max;
self.max := value;
elsif value > self.secmax then
self.secmax := value;
end if;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN SecondMaxImpl, returnValue OUT
number, flags IN number) return number is
begin
returnValue := self.secmax;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT SecondMaxImpl, ctx2 IN
SecondMaxImpl) return number is
begin
if ctx2.max > self.max then
if ctx2.secmax > self.secmax then
self.secmax := ctx2.secmax;
else
self.secmax := self.max;
end if;
self.max := ctx2.max;
elsif ctx2.max > self.secmax then
self.secmax := ctx2.max;
end if;
return ODCIConst.Success;
end;
end;
Create the user-defined aggregate.
CREATE FUNCTION SecondMax (input NUMBER) RETURN NUMBER
PARALLEL_ENABLE AGGREGATE USING SecondMaxImpl;
Using SecondMax()
SELECT SecondMax(salary), department_id
FROM employees
GROUP BY department_id
HAVING SecondMax(salary) > 9000;This could be a x64/x86 problem. Try following this thread
[GetCompanyService|GetCompanyService] and recompile your code for the platform you need. -
Lookiing for example of a user define aggregate function in Java
I want to write an aggregate function in Java. Every example I found is in PL/SQL.
I have written my fair share of JSPs, but this is different in that it is methods off an object.
The documentation says it can be done in Java, but it's not clear to me how to define the ODCIAggregateInitialize, ODCIAggregateIterate, ODCIAggregateTerminate, and ODCIAggregateMerge methods.
If any one can point me to, or send me, an example, I would be very grateful.
TIAHii Greg:
You can find the code to implement a Domain Index for Oracle which uses ODCI Api in Java at.
http://dbprism.cvs.sourceforge.net/viewvc/dbprism/ojvm/src/java/org/apache/lucene/indexer/LuceneDomainIndex.java?revision=1.29&view=markup
This is the code of the implementation of the Lucene Domain Index:
http://docs.google.com/Doc?id=ddgw7sjp_54fgj9kg
The strategy to implement an use aggregate function is similar to implement a Domain Index.
The PLSQL wrapper for the above code is:
http://dbprism.cvs.sourceforge.net/viewvc/dbprism/ojvm/db/LuceneDomainIndex.sql?revision=1.20&view=markup
Take a look at the code and if you have another question just drop me an email or post again into this list.
Best regards, Marcelo. -
Calling PL/SQL user defined functions from ODI Constraints
Hi All,
We are trying to call user defined PL/SQL functions from ODI. We are able to call them from ODI's User functions. But when we are trying to call them from ODI Constraints under Models, it is throwing an error 'ORA-00920 invalid relational operator'. Kindly let me know if anyone has faced the same issue and got the resolution for the same. Thanks in Advance.
Regards,
Abhishek SharmaHi Ace,
Thanks for the response, the same error was coming in operator also.
I am able to call PL?SQL user defined functions from ODI Constraints. We have to first call ODI User functions from the ODI constraints as we cant call PL/SQL function (compiled in database) directly.
From the ODI User functions, we can then call the PL/SQL functions.
Please reach out to me if you need further details reg this. -
SQL User Defined Functions for performing statistical calculations
Hi!
I hope you can help. I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report. The row and columns are going to be displayed in a SQL Server Reporting Services report.
Each row of information contains “Current Month” and “Previous Month” numbers and a variance column. Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring. For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month.
My question is this: Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005? I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure.
I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for. And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure. I’ve asked. They won’t let me do that. I just need to perform the calculation within the stored procedure and return the result.
Any suggestions? Is there a site where people are posting their SQL Server UDF’s to perform statistical functions? Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL? I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
Thanks for your help in advance! Oh, and please let me know if this should have been posted in the TSQL forum instead. I wasn't entirely sure.
Karen GrubeSTATS_T_TEST_
docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm
STATS_T_TEST_ONE: A one-sample t-test
STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances) -
How to call Microsoft SQL User defined function??
I am trying to call Miscrosoft SQL user defined function (not stored procedure) and experience problems. The function -- func_profile_history takes 3 inputs and returns resultSet.
Please let me know if there is any examples some where. All the examples I found are for stored procedure.
Thanks....
Siu
************ source *************
public Vector callSqlFunction(String eidTradcom, String idSku, String endDate, String idUserPost)
throws TradcomException, RemoteException
System.out.println("--------------in callSqlFunction--------------1");
Connection conn = null;
java.sql.CallableStatement cstmt = null;
ResultSet rs = null;
ForecastInfo info = null;
Vector v = new Vector();
try{
conn = TradcomUtils.getConnection();
String sql = "{call func_profile_history(?,?,?)}";
System.out.println("--------------in callSqlFunction--------sql="+sql);
cstmt = conn.prepareCall(sql);
System.out.println("--------------in callSqlFunction-------2");
cstmt.setString(1, eidTradcom);
cstmt.setString(2, idSku);
cstmt.setString(3, endDate);
System.out.println("--------------in callSqlFunction-------3");
rs = cstmt.executeQuery();
System.out.println("--------------in callSqlFunction-------4");
while (rs.next()){
info = new ForecastInfo ();
info.setEidTradcom(rs.getString("eid_tradcom"));
info.setIdSku(rs.getString("id_sku"));
info.setQtOnHand(rs.getDouble("qt_on_hand"));
info.setQtOnHold(rs.getDouble("qt_hold"));
info.setQtNetOnHand(rs.getDouble("qt_net_on_hand"));
info.setQtAlloc(rs.getDouble("qt_alloc"));
info.setQtAvailUnalloc(rs.getDouble("qt_avail_unalloc"));
info.setQtPoShip(rs.getDouble("qt_po_ship"));
info.setQtPoRcvd(rs.getDouble("qt_po_rcvd"));
info.setQtTransit(rs.getDouble("qt_transit"));
info.setQtAsn(rs.getDouble("qt_asn"));
info.setQtPo(rs.getDouble("qt_po"));
info.setQtPoBalance(rs.getDouble("qt_po_balance"));
info.setQtSoShip(rs.getDouble("qt_so_ship"));
info.setQt4Cast(rs.getDouble("qt_4cast"));
v.addElement(info);
System.out.println("--------------in callSqlFunction-------5");
System.out.println("--------------in callSqlFunction-------v="+v);
return v;
}catch(Exception ex){
System.out.println("Error in callSqlFunction:"+ ex.getMessage());
throw CachingManager.getTradcomException(ex, "Error in callSqlFunction");
}finally{
try{ if (cstmt != null) cstmt.close(); } catch(Exception ex){}
try{ if (conn != null) conn.close(); } catch(Exception ex){}
********************* error output ***************
********************* bef calling callSqlFunction
--------------in callSqlFunction--------------1
--------------in callSqlFunction--------sql={call func_profile_history(?,?,?)}
--------------in callSqlFunction-------2
--------------in callSqlFunction-------3
Error in callSqlFunction:The request for procedure 'func_profile_history' failed
because 'func_profile_history' is a function object. Severity 18, State 1, Proc
edure 'LAP_DUAL null', Line 4
ERROR=Error in callSqlFunction...The request for procedure 'func_profile_history
' failed because 'func_profile_history' is a function object. Severity 18, State
1, Procedure 'LAP_DUAL null', Line 4well, I tried the preparedStatemnet and it worked. Case closed.
-
Need help with User Defined Aggregates - Statistical Mode
I would like to use User Defined Aggregates (UDAG) to calculate the Statistical Mode. The mode is the most frequent value among a set of observations.
http://en.wikipedia.org/wiki/Mode_(statistics)
In my application I aggregate an address level table of 130 million records to a ZIP4 level table of roughly 36 million records. Some ZIP4s will have 1 record, some may have 1000+ records. I need to use statistical modes to pick the most frequent values for some of the attribute fields.
Presently I am using an approach from AskTom using the Analytic functions combined with nesting subqueries. The code works but it's cumbersome. I feel user defined aggregates should be able to perform a simpler more straightforward integration into SQL queries.
I've reviewed several of the other posts in this forum on User Defined Aggregates. I feel I could write a procedure that calculates and average or merely concatenates strings. But this particular application of the UDAGs is stumping me. Rather than just increased a running total or count or concatenating a master string, you'd have to keep every distinct values and a count for how many times that value occured. Then evaluate those items to pick the most frequent to pass to output. I'm finding it difficult as a novice.
Any, I'll post a quick example using the present approach that I want to replace with a UDAG:
Here's a small table:
DRD> desc statmodetest
Name Null? Type
ID NUMBER
STATE VARCHAR2(2)
REGION VARCHAR2(1)
1* select * from statmodetest
DRD> /
ID ST REG
1 TX W
2 MN W
3 CA W
4 VA E
5 VA E
6 KY E
7 MN W
8 FL E
9 OK W
10 NC E
11 TX W
12 WI E
13 CA W
14 MI E
15 FL E
16 FL E
17 TN E
18 FL E
19 WI E
20 MA E
Now here's a query approach that gets the MODE State value for each Region.
1 SELECT DISTINCT region, mode_state, mode_state_cnt FROM (
2 SELECT region,
3 FIRST_VALUE(state) OVER (PARTITION BY region ORDER BY stcnt DESC) AS mode_state,
4 FIRST_VALUE(stcnt) OVER (PARTITION BY region ORDER BY stcnt DESC) AS mode_state_cnt
5 FROM (
6 select id, state, region, COUNT(state) OVER (PARTITION BY region, state) AS stcnt
7* from statmodetest t ) )
DRD> /
R MO MODE_STATE_CNT
W CA 2
E FL 4
What I'd like to be able to do is have a UDAG that supports this style query:
SELECT region, UDAGMODE(state)
FROM statmodetest
GROUP BY region ;
Thanks,
PaulThis is not what you want..?
SQL> select * from test;
ID STATU REGIO
1 TX W
2 MN W
3 CA W
4 VA E
5 VA E
6 KY E
7 MN W
8 FL E
9 OK W
10 NC E
11 TX W
12 WI E
13 CA W
14 MI E
15 FL E
16 FL E
17 TN E
18 FL E
19 WI E
20 MA E
20 rows selected.
SQL> select region,max(status) keep(dense_rank first order by cnt desc,status) st,
2 max(cnt)
3 from(
4 select region,status,count(*) cnt
5 from test
6 group by region,status)
7 group by region;
REGIO ST MAX(CNT)
E FL 4
W CA 2
<br>
<br>
Or I misread..? -
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> -
Help! Can I have user defined extension function?
Under SQL Sever XML, I can write a xsl script like this:
<msxsl:script language="JScript" implements-prefix="myfunc">
function getvalue(nodelist,name,istag){
var subNode=nodelist.nextNode();
if(subNode == null) return('?');
if(istag == '') name = '@' + name;
var value=subNode.getElementsByTagName(name);
return((value == null)?'':value);
</msxsl:script>
and I can call this function in the xsl, obviously, msxsl supported by microsoft. I know that Oracle XML support Extension function, but you can tell here that I want a user defined function while not a predefined function. Can I have such feature with Oracle XML, and How? Thanks.Oracle XML support Extension function.
For example:
If we would like to import FAQDBUri.class with user-defined java functions, like TranslateDBUri(), we can write XSL file like this:
<xsl:template match="/" xmlns:dburig="http://www.oracle.com/XSL/Transform/java/FAQDBuri">
<xsl:variable name="urladd" select="dburig:TranslateDBUri($url)"/> -
How can I call a stateful webservice from a user-defined XPath function?
I'm calling a stateful webservice from a BPEL process using a PartnerLink which implements Custom Header Handler classes to handle the session state, storing the cookie as a property of the PartnerLink.
I'd also like to call this same stateful webservice, in the same session, from a user-defined XPath function enabling me to call this from an XSL Transformation.
Is this in any way possible? Can I access the cookie and attach it to the webservice call made by the user-defined XPath function?Actually, as long as the servlet returns valid javascript, you can indeed "call it" from the client. It will initiate a request and return the result to the browser.
This example uses Perl, but it could be easily modified to go to a servlet instead.
Note that it is only supported in DOM browsers (IE6+/NN6+/etc)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> Test server-side JS </title>
</head>
<body>
<script type="text/javascript">
function checkIt(variable, value)
var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
var body = document.getElementsByTagName('body').item(0)
var scriptTag = document.getElementById('loadScript');
if(scriptTag) body.removeChild(scriptTag);
script = document.createElement('script');
script.src = newScript;
script.type = 'text/javascript';
script.id = 'loadScript';
body.appendChild(script)
</script>
<p>Test.</p>
<form id="f1" action="">
<input type="text" name="t1" id="t1" onChange="checkIt(this.name, this.value)">
</body>
</html>
validateJS.cgi
#!/opt/x11r6/bin/perl
use CGI qw(:all);
my @valArray = split(/=/,$ENV{QUERY_STRING});
print "Content-type: text/javascript\n\n";
# myPass is the password
$myPass = "foobar";
if ("$valArray[1]" eq "$myPass")
print "alert(\"Success!!\")";
else
print "alert(\"Failure!!\")"; -
XSLT Mapping - user defined Extension function
Hi to all,
can somebody helps me, please?
I need an own function, that can be used by the XSL Mapper. First I have only tried the sample given in Path <BPELPM>\integration\orabpel\samples\demos\XSLMapper\ExtensionFunctions
There is a java file with the defined functions and a xml file with the definition of this function for the mapper and last but not least a jar-file with the java class.
I have copied the jar to <JDEV_HOME>\jdev\lib\ext directory and in JDeveloper I have added SampleExtensionFunctions.xml to Tools->Preferences->XSL Map -> "User Defined Extension Functions Config File" field. After a restart of JDeveloper I find 2 new functions in the "User Defined Extension Functions" component palette page when a XSL Map is open. That's fine.
But if I test the mapping I get an error: "Failed to transform source XML.
java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xpath.objects.XNodeSet.replaceChar([ExpressionCotext,]#STRING, #STRING)."
What is wrong?
Thanks in advance of your answer
best regard,
unoOracle XML support Extension function.
For example:
If we would like to import FAQDBUri.class with user-defined java functions, like TranslateDBUri(), we can write XSL file like this:
<xsl:template match="/" xmlns:dburig="http://www.oracle.com/XSL/Transform/java/FAQDBuri">
<xsl:variable name="urladd" select="dburig:TranslateDBUri($url)"/> -
Please help for User defined extension functions
the tutorial given for extension functions doesn't work as well as our new functions
even though i follow all the given steps and see the functions in my user defined extension functions tab in xslt map.
all the target nodes that use the extension function disappear in the resulted target xml.
please help.have you compiled your java file and uploaded the jar file(containg the .class file and the Manifest.MF file) in the <OC4J_HOME>\j2ee\home\applib directory and then restarted the server??
-
Component Palette --- "User Defined Extension Functions" not visible
I added a User-Defined XPath Extension Function in JDeveloper 11.1.1.3.0 --> Tools > Preferences > SOA As given here http://download.oracle.com/docs/cd/E15523_01/integration.1111/e10224/bp_appx_functs.htm#BEIHEBIJ
But I am not able see "User Defined Extension Functions" section itself in the component palette. Do I need to enable anything for see the section.
Can somebody help.
ThanksHi,
I am trying to create user defined extension function in JDeveloper 10.1.3.4 to be used with the Oracle ESB.I have followed the documentation provided by the Oracle to resolve this issue without any success can you please help me in providing me the details how did you resolved this issue.
Anticipating your earliest reply
regards
Narasimha
Maybe you are looking for
-
I want to open online files, not download everything I click.
This question applies to both Safari & Firefox. I search for online files to help me with school, could be PDF, PowerPoint, etc. When I click on a file it just downloads them. I want to open 1st and see if I even want the thing. With Windows, it woul
-
HOT Problem connecting with Exporting application!
When I try to export my ApEx application I receive an error: ORA-04030: out of process memory when trying to allocate num 16396 bytes (koh-kghu sessi,pl/sql vc2) Error exporting flow 101. ORA-04030: out of process memory when trying to allocate num 1
-
I have iTunes 11.1.3.8 and when I try update iTunes it is looking for iTunes.msi and can't find the file. I have searched around is there something I can do to fix this without reloading windows. I am also concerned about loosing any information if
-
Suggestion on protecting tabs.
== Issue == I have another kind of problem with Firefox == Description == Suggestion on eyelashes. It would be interesting if the tabs could be "protected", so if you accidentally click in the "x" to close tab, you ask a question of confirmation. ==
-
i download package (Ater-1.2.tar.bz2) and i tried to install him sudo pacman -A /home/chch/Desktop/Ater-1.2.tar.bz2 but i get error loading package data... load_pkg: missing package info file in /home/chch/Desktop/Ater-1.2.tar.bz2