0

I have to use some java function in Oracle SQL Developer. But Im having some troubles with java String parameter. I know my code does nothing with this String. It will be.

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "StringTest" AS
public class StringTest
{ 
    public static int test(String a)
    {
        return 1;
    }
}
/

Which returns:

Java Source StringTest created

Then:

CREATE OR REPLACE FUNCTION F_STRING(input1 in char) return number
as LANGUAGE JAVA NAME 'StringTest.test(String) return int';

Function F_STRING compiled

Now when I try to execute my function:

SELECT F_STRING("some_text") FROM MyTable;

ORA-00904: "some_text": invalid identifier

  1. 00000 - "%s: invalid identifier"

When I try using single quote instead of " I get this:

ORA-29531: no method test in class StringTest 29531. 00000 - "no method %s in class %s" *Cause: An attempt was made to execute a non-existent method in a Java class. *Action: Adjust the call or create the specified method.

Same thing happens when I use varchar2 instead of char. Im sure Im missing something very simple, but can't find solution for like few hours and it already drives me crazy.

0

2 Answers 2

1

When you publishing java method in oracle you have to use full class name. (Canonical Name).

int - is ok , String - is not ok.

Change this

CREATE OR REPLACE FUNCTION F_STRING(input1 in char) return number
    as LANGUAGE JAVA NAME 'StringTest.test(String) return int';

to this.

CREATE OR REPLACE FUNCTION F_STRING(java.lang.String in char) return number
as LANGUAGE JAVA NAME 'StringTest.test(java.lang.String) return int';
Sign up to request clarification or add additional context in comments.

2 Comments

Was trying this at the beginning, but probably made some typo so I abandoned the idea.. Works even without F_STRING(java.lang.String in char) F_STRING(input1 in char) is fine
For primitives types like int, char there is no conical path. For class, this (String, Char) path is required. But I don't understand why it's work with F_STRING(input1 in char). In Oracle varchar2 = varchar =~(almost) = CHAR. In java String != char.
0

Oracle will not tolerate String use java.lang.String instead.

..Also

Not overuse " sign since this forces you to use exact case call to object, since this is not a big problem with java source it may be with other objects.

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED stringtest AS
public class StringTest
{
    public static int test(String a)
    {
        return 1;
    }
}


CREATE OR REPLACE FUNCTION F_STRING(input1 in char) return number
as LANGUAGE JAVA NAME 'StringTest.test(java.lang.String) return java.lang.Intiger';


SELECT F_STRING('some_text') FROM dual;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.