Reputation: 43013
Here is my code:
SET DEFINE OFF;
CREATE OR REPLACE AND COMPILE NOFORCE JAVA SOURCE NAMED "SCHEMA"."DigestUtils" AS
/* imports here... */
public class DigestUtils {
private static final char[] hexCode = "0123456789ABCDEF".toCharArray();
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
public static String sha512Hex(Clob c) throws MyException {
// Code here ...
return "Hex.string.here";
}
private static class MyException extends Exception {
private static final long serialVersionUID = 8501244872025707585L;
public MyException(Throwable cause) {
super(cause);
if ((cause instanceof SQLException) && !(cause instanceof SQLWarning) && (DriverManager.getLogWriter() != null)) {
printStackTrace(DriverManager.getLogWriter());
}
}
}
}
;
CREATE OR REPLACE FUNCTION sha512Hex RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'DigestUtils.sha512Hex(java.sql.Clob) return java.lang.String';
when I try to call the Java stored procedure from SQL like below:
select clob_column, sha512Hex(clob_column)
from my_table
where id in (49917,49918,49919,60455)
I get this error:
ORA-06553: PLS-306: numéro ou types d'arguments erronés dans appel à 'sha512Hex'
06553. 00000 - "PLS-%s: %s"
*Cause:
*Action:
Error on line 196, column 17 (translated from original message)
Here is the error line:
(l. 196) select clob_column, sha1Hex(clob_column)
^
|___ column 17
What am I missing?
Oracle 10gR2
Java 1.4.2 (embedded in Oracle)
Upvotes: 1
Views: 170
Reputation: 43013
This answer completes Alex Poole's one.
Here is how to describe a function with a plain SQL query:
SELECT
argument_name
,pls_type
--,data_type -- may contain useful info
,in_out
,default_value
FROM
user_arguments -- replace with ALL_ARGUMENTS for functions you don't own
WHERE
object_name = 'SHA1HEX'
ORDER BY
position
ARGUMENT_NAME PLS_TYPE IN_OUT DEFAULT_VALUE
---------------- -------------- --------- --------------
<null> VARCHAR2 OUT <null>
C CLOB IN <null>
Upvotes: 1
Reputation: 191275
If you describe your current function you'll see:
desc sha512Hex
Argument Name Type In/Out Default
-------------- -------- ------ -------
<return value> VARCHAR2 OUT unknown
Your PL/SQL function declaration needs to define the argument and its type too:
CREATE OR REPLACE FUNCTION sha512Hex(c CLOB) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'DigestUtils.sha512Hex(java.sql.Clob) return java.lang.String';
desc sha512Hex
Argument Name Type In/Out Default
-------------- -------- ------ -------
<return value> VARCHAR2 OUT unknown
C CLOB IN unknown
You can then call that as you were attempting to in your question.
Upvotes: 3