select * from nls_database_parameters; … NLS_CHARACTERSET … NLS_LENGTH_SEMANTICS BYTE … NLS_NCHAR_CHARACTERSET NLS_RDBMS_VERSION |
SQL> SQL> create table nls_byte(c1 varchar2(7)); SQL> insert into nls_byte values('测试机'); insert into nls_byte values('测试机') SQL> insert into nls_byte values('测试a'); |
SQL> select table_name,column_name,t.DATA_TYPE,t.DATA_LENGTH,t.CHAR_USED from user_tab_columns t where table_name='NLS_BYTE'; TABLE_NAME COLU DATA_TYP DATA_LENGTH CHAR_USED ---------- ---- -------- ----------- --------- NLS_BYTE |
NLS_LENGTH_SEMANTICS 这个参数允许将列的数据单位设为字符而不是byte.这个问题会在字符集设为UTF8的时候出现. 此参数在9i以上版本有效.
NLS_LENGTH_SEMANTICS 设置.
1.
2.
3.
4.
5.
6.
7.
8.
测试:
一.在当前session中修改此参数
SQL> alter session set nls_length_semantics='char'; Session altered SQL> create table nls_char(c1 varchar2(7),c2 varchar2(7)); Table created SQL> desc nls_char Name Type ---- ----------- -------- ------- -------- C1 C2 SQL> insert into nls_char values('测试机','测试测试测试'); 1 row inserted |
如果对于alter system,效果是一样的
二.对于已经存在的表,
SQL> desc nls_byte Name Type ---- ---------------- -------- ------- -------- C1 SQL> alter table nls_byte modify c1 varchar2(7 char); SQL> desc nls_byte Name Type ---- ----------- -------- ------- -------- C1 SQL> insert into nls_byte values('测试机'); 1 row inserted |
1.
*可以预先在目标库中以char方式建表
*然后导入,指定参数ignore=y
alter table "<owner>"."<table>" modify "<column>" char (10 char);
创建脚本
,
修改列设定
.
注
:
Bug-3611750, ora-01450 online rebuild of index fails,
可以在重建索引前指定
byte, 10.2.0.5
以上已经修复
Bug 1488174 UNICODE: ALTER SYSTEM SET NLS_LENGTH_SEMANTICS DOESN'T
TAKE EFFECT, 用此语句修改后,实际上不起作用,需要重启才能生效, 但是如果用alter session方式即时生效,不用重启.
进一步测试,在另一个字符集设为us7ascii的DB设置此参数
SQL> select * from nls_database_parameters 6 SQL> alter session set nls_length_semantics=byte; Session altered. SQL> create table nls_byte(c1 varchar2(7)); Table created. SQL> insert into insert into ERROR at line 1: ORA-12899: value too large for column "TEA"."NLS_BYTE"."C1" (actual: 8, maximum: 7) SQL> desc nls_byte SQL> alter session set nls_length_semantics=char; Session altered. SQL> create table nls_char(c1 varchar2(7)); Table created. SQL> insert into insert into ERROR at line 1: ORA-12899: value too large for column "TEA"."NLS_CHAR"."C1" (actual: 8, maximum: 7) SQL> desc nls_char C1 |
可以看出,在字符集为单字节的情况下,无论取何值,汉字都是以二个字节的方式存在的.