How to include Java functions(and external libraries too) in Oracle PL\SQL?

一世执手 提交于 2020-01-23 12:37:09

问题


I've a function in Java that uses an external library (jackson) to work with JSON structures. How can I include my function and all its dependencies in Oracle(12c) PL\SQL? The DB host is an unix os.


回答1:


You need to compile your project as fat jar. It means a jar that includes its dependencies on it. Using with zip opener, you can open a fatjar and find jar dependencies in parent fatjar.

After you create your project on unix os which your db runs on go to jar path and run the code below

$ > loadjava -user userName/password@dbName FirstFatJar.jar 

Now you uploaded your jar to oracle. And assume that you have a java class in jar that name is Master and it has a function that name is Atesle which returns java.lang.String. Than connect your oracle db and create java stored procedure/function like that

CREATE or replace FUNCTION atesle1 RETURN VARCHAR2  AS LANGUAGE JAVA NAME 'Master.atesle() return java.lang.String';

Now you can run your java code via oracle store procedure with code below;

select atesle1() from dual


来源:https://stackoverflow.com/questions/43782772/how-to-include-java-functionsand-external-libraries-too-in-oracle-pl-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!