views:

207

answers:

2

Given the following Java which is loaded into the database using loadjava:

package grassie.example;

public class Example {

    public static String test(){
        return "Hello World!";
    }
}

And given the following Oracle Stored Function:

CREATE OR REPLACE FUNCTION TEST_FUNCTION RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'grassie.example.Example.test() RETURN java.lang.String';

Why does the function not compile with the following error?:

Error(3,1): PLS-00311: the declaration of "grassie.example.Example.test() RETURN java.lang.String" is incomplete or malformed

Oracle client is 9.2.0.8.0, database is 9.2.0.8.0. Using SQL Developer 2.1.0.63

edit: Ammended my question based on answers below.

To further clarify, I created this simple test class and function because I am having problems with more complicated Java and stored functions, which accept and return various parameter types.

+1  A: 

Hi sgrassie,

if the function has no parameters you don't need parentheses ():

SQL> CREATE OR REPLACE FUNCTION TEST_FUNCTION() RETURN NUMBER AS
  2  BEGIN
  3     RETURN 0;
  4  END;
  5  /

Warning: Function created with compilation errors

SQL> CREATE OR REPLACE FUNCTION TEST_FUNCTION RETURN NUMBER AS
  2  BEGIN
  3     RETURN 0;
  4  END;
  5  /

Function created
Vincent Malgrat
+1  A: 

Get rid of the empty parentheses in the function declaration:

CREATE OR REPLACE FUNCTION TEST_FUNCTION RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'grassie.example.Example.test() RETURN java.lang.String';

Update:

Java keywords should be lowercase. Try replacing RETURN with return in the NAME clause.

Quassnoi
I do that, I get the following error: `Error(3,1): PLS-00311: the declaration of "grassie.example.Example.test() RETURN java.lang.String" is incomplete or malformed`
sgrassie