鉴于Oracle中的这个表
create table test (bytes raw(100), chset varchar2(50))
insert into test (bytes, chset) values (hextoraw('454647'), 'iso-8859-1')
Run Code Online (Sandbox Code Playgroud)
或者在MSSQL中
create table test (bytes varbinary(100), chset nvarchar(50))
insert into test (bytes, chset) values (0x454647, 'iso-8859-1')
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个全面的例子,说明如何使用Java的文本编码支持在Java中创建Oracle的UDF.
在MSSQL中我会创建这个.Net程序集:
using System.Text;
using Microsoft.SqlServer.Server;
namespace Whatever
{
public class Common
{
[SqlFunction]
public static string Decode(byte[] Bytes, string EncodingName)
{
return Encoding.GetEncoding(EncodingName).GetString(Bytes);
}
}
}
Run Code Online (Sandbox Code Playgroud)
并使用这些命令注册程序集并定义udf:
create assembly MyAssembly from '...\MyAssembly.dll'
create function decode(@bytes varbinary(max), @chset nvarchar(100))
returns nvarchar(max) as external name MyAssembly.[Whatever.Common].Decode
Run Code Online (Sandbox Code Playgroud)
并在这样的查询中使用它:
> select …Run Code Online (Sandbox Code Playgroud) java sql oracle user-defined-functions java-stored-procedures