12
返回列表 发新帖
楼主: wyj243

对oracle varchar2(..... char)的疑惑

[复制链接]
论坛徽章:
8
2009新春纪念徽章
日期:2009-01-04 14:52:28祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:07:24ITPUB9周年纪念徽章
日期:2010-10-08 09:32:25ITPUB十周年纪念徽章
日期:2011-11-01 16:23:262013年新春福章
日期:2013-02-25 14:51:24沸羊羊
日期:2015-03-04 14:51:522015年新春福章
日期:2015-03-06 11:57:31
11#
发表于 2010-6-30 15:53 | 只看该作者
1、这和数据库的字符集有关系,楼主的字符集是SIMPLIFIED CHINESE_CHINA.ZHS16GBK,一个汉字在这个字符集中应该占用两个字节,因此,楼主的表中A字段最多只能存储4000/2=2000个汉字;
2、nls_length_semantics说明长度的默认意义,即length得出的值的默认单位,但在varchar2(4000 char)中,覆盖了该参数的默认值,即该字段最大可以存储4000个字符而不是字节,length()返回的也是字符数,而不是字节数;
3、just_dba的试验中就说明了这点,只是他的数据库中一个汉字占用了三个字节,所以最终在试验中只插入了1333个汉字:3*1333=3999;
4、下面是ORACLE官方资料的一段,大家可以参考:
Oracle® Database
SQL Language Reference
11g Release 1 (11.1)
B28286-02
September 2007

P44

You must specify a maximum length for a VARCHAR2 column. This maximum must be
at least 1 byte, although the actual string stored is permitted to be a zero-length string
(''). You can use the CHAR qualifier, for example VARCHAR2(10 CHAR), to give the
maximum length in characters instead of bytes. A character is technically a code point
of the database character set. CHAR and BYTE qualifiers override the setting of the
NLS_LENGTH_SEMANTICS parameter, which has a default of bytes. For performance
reasons, Oracle recommends that you use the NLS_LENGTH_SEMANTICS parameter to
set length semantics and that you use the BYTE and CHAR qualifiers only when
necessary to override the parameter. The maximum length of VARCHAR2 data is 4000
bytes. Oracle compares VARCHAR2 values using nonpadded comparison semantics.

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
12#
发表于 2010-7-1 00:27 | 只看该作者
dingjun123 and sqysl are correct. I missed the point that "The maximum length of VARCHAR2 data is 4000 bytes". At the time you define varchar2(4000 char) or varchar2(3000 char), Oracle won't complain, because it doesn't know if your char will be more than 1 byte. When you actually insert data, the limit of 4000 bytes kicks in.

Yong Huang

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表