Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: java class wrapper
"Marcin Buchwald" <velvet_at_agora.pl> writes:
> I wrote the class that computes GCD. > > public class GCD { > public static int calcGCD( int[] array ) { /* ... */ } > } > > Is it possible tu use it as agregate function in sql. How to write a > wrapper to it? The problem is in datatypes. I wrote something like: > > (n0 number, n1 number, n2 number) return number as > language java name 'GCD_LCM.calcGCD(int[]) return int'; > or > (n0 myNumberList) return number as > language java name 'GCD_LCM.calcGCD(int[]) return int';
Try to use BigInteger or BigDecimal. The following example works for me:
,----[ NumberArray.java ]
| import java.math.*;
|
| public class NumberArray {
| public static int test(BigInteger [] arr ){
| return 0;
| }
| }
`----
,----[ NumberArray.sql ]
| connect scott/tiger;
|
| create or replace type NumberArray_type as table of number;
| /
|
| create or replace function NumberArray_test( abc NumberArray_type)
| return number as
| language java name 'NumberArray.test(java.math.BigInteger []) return int';
| /
|
| declare
| arr NumberArray_type;
| res int;
| begin
| null;
| res := NumberArray_test(arr);
| end;
| /
`----
Harald Received on Sun Sep 28 2003 - 02:14:12 CDT
![]() |
![]() |