How to call sample helloword func using a java code

135 views Asked by At

I am new to Functions as a service. I have done all the relavant setup and get below output for command command : fn invoke helloworld-app helloworld-func Output: Hello, world!

Now I need to invoke the helloworld-func using java client code which can run on any location. Is it possible ? If yes how ?

1

There are 1 answers

0
MT0 On

In Oracle RDBMS you can compile a java source:

CREATE AND COMPILE JAVA SOURCE NAMED helloworld_app_source AS
public class helloworld_app {
  public static String helloworld_func()
  {
    return "Hello, world!";
  }
}

Then you can wrap it in an Oracle function:

CREATE FUNCTION helloworld_func RETURN VARCHAR2
AS LANGUAGE JAVA NAME 'helloworld_app.helloworld_func() return java.lang.String';
/

Then you can just call it in an normal SQL statement (as per any other function):

SELECT helloworld_func() FROM DUAL;

The Java function will run on the server but the query can be invoked from any SQL client connected to the server and will return the output to that client.