国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

Oracle的函數vsize和length的區別討論

2024-08-29 13:34:04
字體:
來源:轉載
供稿:網友
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

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1492768

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霞浦县| 肥乡县| 郧西县| 安乡县| 达日县| 利川市| 临清市| 岢岚县| 丽江市| 承德市| 公安县| 霍山县| 当涂县| 贞丰县| 宁波市| 海城市| 九台市| 天峻县| 塘沽区| 通州区| 岑巩县| 锡林郭勒盟| 宁河县| 阿拉善右旗| 紫阳县| 安图县| 石棉县| 云浮市| 昌都县| 略阳县| 平塘县| 洪湖市| 上杭县| 呼玛县| 家居| 万山特区| 车致| 麦盖提县| 安庆市| 江山市| 衡南县|