--GBK编码,一个汉字占用两个字节
--UTF-8编码,一个汉字占用三个字节。
--两种编码下 英文、数字均占用一个字节
--查询数据库编码
select userenv('language') from dual;
--lengthb 求得字节长度
select lengthb('123') from dual //3
select lengthb('哈哈哈') from dual //9 (此时数据库编码为:SIMPLIFIED CHINESE_CHINA.AL32UTF8)
--length 求得字符长度
select length('123') from dual //3
select length('哈哈哈') from dual //3
附:java中代码,演示了不同编码所占用的字节数
public static void main(String[] args) throws UnsupportedEncodingException {
String a = "中国人";
String b = "abc";
System.out.println(a.length()); //3
System.out.println(a.getBytes().length); //9
System.out.println("=====");
System.out.println(b.length()); //3
System.out.println(b.getBytes().length); //3
System.out.println("====");
//gbk:英文一个字符占用一个字节,中文一个字符占用两个个字节
//utf-8:英文一个字符占用一个字节,中文一个字符占用三个字节
//所以,英文多的论坛,utf-8更节省空间
byte[] a_gbk = a.getBytes("GBK");
byte[] a_utf = a.getBytes("UTF-8");
System.out.println(a_gbk.length); //6
System.out.println(a_utf.length); //9
System.out.println("====");
byte[] b_gbk = b.getBytes("GBK");
byte[] b_utf = b.getBytes("UTF-8");
System.out.println(b_gbk.length); //3
System.out.println(b_utf.length); //3
System.out.println("====");
String c = new String(b_gbk,"GBK");
System.out.println(c.getBytes().length); //3
}