Thursday, November 21, 2013

Simple Step to Execute Java Programe from Oracle

Step 1
Write java prg and compile from Oracle bin folder
public class Hello
{
  public static String world()
  {
    return "Hello world";
  }
}
D:\app\oracle\product\11.1.0\db_1\BIN>javac  -target 1.5 Hello.java
------------------------------------------------------------------------
Step 2
load the class file
D:\app\oracle\product\11.1.0\db_1\BIN>loadjava -user hr/hr Hello.class
-------------------------------------------------------------------------
Step 3
Write a plsql function in SQL
CREATE OR REPLACE FUNCTION helloworld RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'Hello.world () return java.lang.String';
/
------------------------------------------------------------------------
Step 4
select helloworld() from dual;
Hello world

1 comment:

Unknown said...

Thanks for sharing, it is very useful for DB developers