gpt4 book ai didi

java - 从 Oracle 函数调用 Java 函数

转载 作者:行者123 更新时间:2023-12-02 11:07:36 25 4
gpt4 key购买 nike

我已经在 Oracle 中创建了 Java 类,但不确定如何创建函数来返回值。任何帮助,将不胜感激。

create or replace and compile java source named "ErrorMessage" 
as
import java.util.zip.Inflater;
public class ErrorMessage {
public static String uncompressMessage(byte[] cdata, int uncompressedLength){
String uncompData2 = null;
try{

Inflater inflater = new Inflater();
inflater.setInput(cdata);
Byte [] uncompData = new byte[uncompressedLength];
int n = inflater.inflate(uncompData);
uncompData2 = uncompData.toString();
inflater.end();

}catch (Exception e){
e.getMessage();
}
return uncompData2;
}
}

create or replace
function getErrorMessage(msgdata blob, msgdatalength integer)
return varchar2
as language java
name 'ErrorMessage.uncompressMessage(byte[],int)
return java.lang.String';

最佳答案

类似于:

create or replace and compile java source named "ErrorMessage" 
as
import java.util.zip.Inflater;
import java.lang.Byte;
import java.sql.Blob;

public class ErrorMessage {
public static String uncompressMessage( Blob data, int uncompressedLength ){
String uncompData2 = null;
try{
final long size = data.length();
final byte[] cdata = data.getBytes( 0L, (int) size );
Inflater inflater = new Inflater();
inflater.setInput( cdata );
byte[] uncompData = new byte[uncompressedLength];
int n = inflater.inflate(uncompData);
uncompData2 = new String( uncompData, "UTF-8" );
inflater.end();
}catch (Exception e){
e.getMessage();
}
return uncompData2;
}
}
/

create or replace function getErrorMessage(msgdata blob, msgdatalength number) return varchar2
as language java
name 'ErrorMessage.uncompressMessage(java.sql.Blob,int) return java.lang.String';

关于java - 从 Oracle 函数调用 Java 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50845101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com