Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: BITAND with large integers
"Raj Jamadagni" <rajsun_no_spam_at_email.com> wrote in message
news:5oydneL2qtvD8n-iRVn-uA_at_comcast.com...
> Matt,
> can you give us a couple of examples?
> Thanks
> Raj
>
Here is an example. Please keep in mind I'm not experienced with Java, so the Jave code below is not good code. However, it demonstrates the example.
At SQL prompt:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Mathematics" AS
import java.lang.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class Mathematics
{
public static long lbitand (long Number1, long Number2)
{
try
{
long iReturn = Number1 & Number2;
return iReturn;
}
catch (Exception e)
{
return -1;
}
}
};
/
show errors java source "Mathematics"
CREATE OR REPLACE FUNCTION lbitand (p_number1 IN NUMBER, p_number2 IN
NUMBER) RETURN NUMBER
AS LANGUAGE JAVA
NAME 'Mathematics.lbitand (long, long) return long';
/
SELECT LBITAND(4, POWER(2,31))
FROM dual;
SELECT TO_NUMBER(BITAND(4, POWER(2,31))) FROM dual;
The first SQL example uses user-defined function LBITAND.
Second example uses Oracle built-in function BITAND.
Note that the BITAND gives the wrong answer in the example above because it does not correctly handle the large second agrument.
The above is from my notes. I hope it is accurate and works.
Matt. Received on Sun Dec 21 2003 - 21:44:41 CST