March 04, 2013

Calling Java Procedure in SQL


Loadjava Utility

Step 1: Create or Reuse the Java Classes

public class orclJavaTest {
  public static String quote() {
    return "Wow! Implementing java Stored Procedure in database";
  }
}


Step 2: Load and Resolve the Java Classes


Please note that in first two cases, I compiled it agianst Java 1.6 and got ORA-29552 error. It compiled successfully when forcefully compiled under 1.5

Step 3: Publish the Java Classes

drop function orclJava;
create or replace function orclJava return varchar2 as language java
name 'orclJavaTest.quote() return java.lang.String';
/
alter system set java_jit_enabled=false;

select * from all_objects y where upper(y.object_name) like '%ORCL%'

SBI    orclJavaTest    JAVA CLASS    2012-02-14:11:41:31    VALID SBI    ORCLJAVA        FUNCTION      2012-02-14:11:42:18    VALID


Step 4: Call the Stored Procedures

SQL> select orclJava() from dual;

ORCLJAVA()
---------------------------------------------------
Wow! Implementing java Stored Procedure in database



No comments:

Post a Comment