0

When trying to create oracle SQL java function to generate random UUID as described in this StackOverflow answer, I get following error:

sql> CREATE or REPLACE FUNCTION random_uuid
   RETURN VARCHAR2
   AS LANGUAGE JAVA NAME 'java.util.UUID.randomUUID() return java.lang.String'
[2019-01-29 09:28:29] [99999][17110] Warning: execution completed with warning
[2019-01-29 09:28:29] completed in 23 ms
[2019-01-29 09:28:29] 3:78:PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
[2019-01-29 09:28:29] ;
[2019-01-29 09:28:29] The symbol ";" was substituted for "end-of-file" to continue.

Even this is just a warning, calling it does not work afterwards:

sql> select random_uuid() from dual
[2019-01-29 09:36:28] [65000][6575] ORA-06575: Package or function RANDOM_UUID is in an invalid state

I use IntelliJ IDEA's Database Console to execute the script. What is wrong?

EDIT: Mine original script does contain semicolon at the end:

create or replace function random_uuid return varchar2 as
  language java
  name 'java.util.UUID.randomUUID() return String';

Adding ';' after the String does not help:

create or replace function random_uuid return varchar2 as
  language java
  name 'java.util.UUID.randomUUID() return String;';
5
  • So why don't you add the requested ';'? Commented Jan 29, 2019 at 8:51
  • Is it possible to share java code? Commented Jan 29, 2019 at 10:32
  • There is no java code apart from the "java.util.UUID.randomUUID()" in the script. I'm just trying to execute the script within Database Console of IntelliJ IDEA. This seems to be caused by the parsing: Database Console treats the semicolon at the end as statement delimiter and therefore semicolon is missing for the statement. Same problem with dbvis but it is possible to mark the block with "--/" and "-" there. Commented Jan 29, 2019 at 11:02
  • Check if class is valid SELECT * FROM dba_objects WHERE object_type IN ('JAVA CLASS') and object_name = 'java/util/UUID'; Commented Jan 29, 2019 at 11:57
  • IntelliJ IDEA bug reported: youtrack.jetbrains.com/issue/DBE-7723 Commented Jan 30, 2019 at 8:53

1 Answer 1

1

Since the problem appears to be the IDE not recognising where the statement terminates then you can try to wrap it in a PL/SQL anonymous block and use EXECUTE IMMEDIATE to force it to parse the statement correctly:

BEGIN
  EXECUTE IMMEDIATE 'CREATE OR REPLACE FUNCTION RandomUUID RETURN VARCHAR2 AS LANGUAGE JAVA NAME ''java.util.UUID.randomUUID() return java.lang.String'';';
END;
/
Sign up to request clarification or add additional context in comments.

1 Comment

'java.util.UUID.randomUUID() return String' works just fine when creating the function using dbvis and SQL block delimiters: confluence.dbvis.com/display/UG100/Executing+Complex+Statements

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.