The length functions return the length of char LENGTH calculates length using characters as defined by the input character set
LENGTHB uses bytes instead of characters LENGTHC uses Unicode complete characters LENGTH uses UCS codepoints LENGTH uses UCS codepoints
length函数返回字符的长度它使用定义好的输入的字符集计算长度
lengthb使用bytes代替字符
VSIZE returns the number of bytes in the internal representation of expr
vsize 返回内部表示的字节的数目internal representation of expr谁能解释一下
看sql示例
select length(adfad合理) bytesLengthIs from dual
select lengthb(adfad) bytesLengthIs from dual
select lengthb(adfad合理) bytesLengthIs from dual
select vsize(adfad合理) bytesLengthIs from dual
select lengthc(adfad合理)bytesLengthIs from dual
结论在utf的字符集下
lengthb=vsize
lengthc=length
疑问中文字符怎么会占用了个byte?而不是个是utf字符集的原因?
谁知道??????
参考文献Oraclei SQL Reference Release ()
用String的getBytes方法测试了一下
结论是utf的中文字符占用个字节gbk的中文字符占用个字节iso的中文字符被识别为占用个字节iso不支持中文字符的编码应该是都当成某个拉丁字母了Oracle没有关系oracle只是负责存储数据
可以先用 select * from v$nls_parameters 看看oracle的字符集
下边是测试的类:
import javaioUnsupportedEncodingException;
public class TextEncoding {
/**
*
* @author:sunflower
* @date: 上午::
* @todo: 调用的是String的自己的getBytes(encoding)方法
* 使用指定的字符集将此 String 解码为字节序列并将结果存储到一个新的字节数组中
* @param content
* @param encode
* @return
*/
public static byte[] getBytes(String contentString charsetName)
throws UnsupportedEncodingException{
return contentgetBytes(charsetName);
}
/**
*
* @author:sunflower
* @date: 上午::
* @todo: 调用的是String的自己的getBytes()方法
* 使用平台默认的字符集将此 String 解码为字节序列并将结果存储到一个新的字节数组中
* @param content
* @return
*/
public static byte[] getBytes(String content){
return contentgetBytes();
}
public static void main(String[]args){
String content=e宝宝;
byte[] len;
try{
len=getBytes(contentUTF);
Systemoutprintln( the byte array length is +lenlength);
len=getBytes(contentGBK);
Systemoutprintln( the byte array length is +lenlength);
len=getBytes(contentISO);
Systemoutprintln( the byte array length is +lenlength);
}catch(Exception e){
Systemoutprintln(Can t recognize);
}
// Systemoutprintln(the content byte[] length is +);
}
}
输出 :
the byte array length is
the byte array length is
the byte array length is
Trackback: x?PostId=