前提是数据库上需要安装java虚拟机(JVM),使用下面的语句查看
- select * from dba_registry where comp_id = 'JAVAVM'
select * from dba_registry where comp_id = 'JAVAVM'
为空,则未安装,请执行 $ORACLE_HOME/javavm/install/initjvm.sql安装.
创建函数
- create or replace function fn_oraclecall(mArea in VARCHAR2,mDevID in Number,mPORT in Number)
- return varchar2
- as
- language java name 'Caller.call(java.lang.String,Integer,Integer) return java.lang.String';
create or replace function fn_oraclecall(mArea in VARCHAR2,mDevID in Number,mPORT in Number)
return varchar2
as
language java name 'Caller.call(java.lang.String,Integer,Integer) return java.lang.String';
创建存储过程
- create or replace procedure CHK_SETCAB_NUM
- (mArea in VARCHAR2,mDevID in Number,mPORT in Number,v_out out varchar2) is
- begin
- v_out := fn_oraclecall(mArea,mDevID,mPORT);
- end CHK_SETCAB_NUM;
create or replace procedure CHK_SETCAB_NUM
(mArea in VARCHAR2,mDevID in Number,mPORT in Number,v_out out varchar2) is
begin
v_out := fn_oraclecall(mArea,mDevID,mPORT);
end CHK_SETCAB_NUM;
loadjava
- loadjava -u sys/sys@sid -oci8 -verbose -grant user -synonym -resolve -schema user D:\Caller.jar
- --这里也可以是class文件,注意兼容oracle的jre版本
loadjava -u sys/sys@sid -oci8 -verbose -grant user -synonym -resolve -schema user D:\Caller.jar
--这里也可以是class文件,注意兼容oracle的jre版本
注意编写的java文件里,即Caller.java的call()方法,需要是staic