首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > Oracle的函数vsize和length的区别讨论
【标  题】:Oracle的函数vsize和length的区别讨论
【关键字】:Oracle,vsize,length
【来  源】:http://blog.csdn.net/rainv/archive/2007/01/25/1492768.aspx

Oracle的函数vsize和length的区别讨论

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. LENGTH2 uses UCS2 codepoints. LENGTH4 uses UCS4 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 --7

select lengthb('adfad') "bytesLengthIs" from dual --5

select lengthb('adfad合理') "bytesLengthIs" from dual --11

select vsize('adfad合理') "bytesLengthIs" from dual --11

select lengthc('adfad合理')"bytesLengthIs" from dual --7

结论:在utf-8的字符集下
lengthb=vsize
lengthc=length

疑问:中文字符怎么会占用了3个byte?而不是2个。是utf-8字符集的原因?
谁知道??????

参考文献:Oracle9i SQL Reference Release 2 (9.2)
 

........................................................................................................................................................................

用String的getBytes方法测试了一下.
结论是utf-8的中文字符占用3个字节,gbk的中文字符占用2个字节,iso-8859-1的中文字符被识别为占用2个字节,iso不支持中文字符的编码,应该是都当成某个拉丁字母了.Oracle没有关系,oracle只是负责存储数据.
可以先用 select * from v$nls_parameters 看看oracle的字符集
下边是测试的类:

import java.io.UnsupportedEncodingException;

public class TextEncoding {

/**
*
* @author:sunflower
* @date: 2007-1-24 上午10:09:40
* @todo: 调用的是String的自己的getBytes(encoding)方法,
* 使用指定的字符集将此 String 解码为字节序列,并将结果存储到一个新的字节数组中.
* @param content
* @param encode
* @return
*/
public static byte[] getBytes(String content,String charsetName)
throws UnsupportedEncodingException{
return content.getBytes(charsetName);
}

/**
*
* @author:sunflower
* @date: 2007-1-24 上午10:19:40
* @todo: 调用的是String的自己的getBytes()方法,
* 使用平台默认的字符集将此 String 解码为字节序列,并将结果存储到一个新的字节数组中。
* @param content
* @return
*/
public static byte[] getBytes(String content){
return content.getBytes();
}

public static void main(String[]args){
String content="1e宝宝";
byte[] len;
try{
len=getBytes(content,"UTF-8");
System.out.println(" the byte array length is "+len.length);
len=getBytes(content,"GBK");
System.out.println(" the byte array length is "+len.length);
len=getBytes(content,"ISO-8859-1");
System.out.println(" the byte array length is "+len.length);
}catch(Exception e){
System.out.println("Can 't recognize");
}

// System.out.println("the content byte[] length is "+);
}

}

输出 :
the byte array length is 8
the byte array length is 6
the byte array length is 4

 

ABAP FAQs:【上一篇】
异构数据集成视频,AVI格式:【下一篇】
【相关文章】
  • 记几个容易忘的oracle 函数
  • 如何oracle调试存储过程
  • 把dmp文件导入oracle中
  • ado.net执行oracle 存储过程
  • Oracle SQL 性能优化技巧
  • Oracle 游标使用
  • ORACLE:"ORA-:内部错误,hostdef扩展名不存在"
  • ORACLE:Orcale与Asp.net的端口冲突
  • ORACLE:Oracle默认端口清单以及修改办法
  • Oracle DML封锁机制研究
  • 【随机文章】
  • Perl实现MP3在线播放Web服务器
  • 点点滴滴
  • SCSI硬盘低级格式化
  • 软件推荐:思维导图(FreeMind)
  • JAVA JDK5.0 泛型编程 (图)
  • 网页中META标签的使用
  • JSP+MySQL乱码问题 (3)
  • [编译错误] error LNK2001: 无法解析的外部符号
  • 一道Sql语句问题?
  • 红旗软件、Miracle Linux、Haansoft共同预发布基于2.6核心的Asianux2.
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.