Java过程修改dump文件成特定字符集
http://www.itpub.net/viewthread.php?tid=49880&highlight=%D7%D6%B7%FB%BC%AF
前一段时间在
http://www.itpub.net/showthread. ... 15&pagenumber=1
中讨论的DMP不同字符集之间自由转换工具,经过一位java朋友的帮忙,今天奉献上biti提议的java存储过程修改方法:
DumpChange.java脚本:
import java.io.*;
public class DumpChange
{
public static String ChangeCharSet(String fileName,String value)
throws IOException,NumberFormatException
{
try
{
value=value.trim();
if(value.length()<4)
value=new String("0000"+value).substring(value.length());
else if(value.length()>4)
throw new NumberFormatException(value+"is error,length>4.";
RandomAccessFile raf=new RandomAccessFile(fileName,"rw";
byte[] bts=new byte[2];
bts[0]=new Integer(Integer.parseInt(value.substring(0,2),16)).byteValue();
bts[1]=new Integer(Integer.parseInt(value.substring(2),16)).byteValue();
raf.seek(1);
raf.write(bts);
raf.close();
return "OK";
}
catch(Exception e)
{
return e.toString();
}
}
}
C:\>loadjava -user scott/tiger@ora8db1 -r -f -v c:\yztbak\DumpChange.java
initialization complete
loading : DumpChange
creating : DumpChange
resolver :
resolving: DumpChange
C:\>sqlplus /nolog
SQL*Plus: Release 8.1.7.0.0 - Production on Tue Aug 13 15:35:00 2002
(c) Copyright 2000 Oracle Corporation. All rights reserved.
SQL> conn sys/change_on_install@ora8db1 as sysdba
Connected.
SQL> CREATE OR REPLACE FUNCTION SCOTT.DumpCharSet(FileName in varchar2,HexCharSe
t in varchar2) return varchar2 as language java name 'DumpChange.ChangeCharSet(j
ava.lang.String,java.lang.String) return java.lang.String';
2 /
Function created.
SQL> CREATE OR REPLACE FUNCTION SCOTT.TO_CHARSET
2 (Filename in varchar2,CharSet in varchar2) return varchar2
3 as
4 HexId varchar2(10);
5 ret varchar2(500);
6 begin
7 select to_char(NLS_CHARSET_ID(CharSet),'xxxx') into HexId from dual;
8 HexId:=trim(HexId);
9 select DumpCharSet(Filename,HexId) into ret from dual;
10 return ret;
11 end;
12 /
No comments:
Post a Comment