首页 > 应用开发 > IT综合 > 关于nls_length_semantics
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 allows you to specify the length of a column datatype in terms of CHARacters rather than in terms of BYTEs. Typically this is when using an AL32UTF8 or other varying width NLS_CHARACTERSET database where one character is not always one byte. While using CHAR semantics has as such no added value in a 7/8 bit characterset it's fully supported so any application code / table setup using CHAR can also be used in a 7/8bit characterset like US7ASCII/WE8MSWIN1252.
This parameter is a 9i (and up) feature and is not available in older releases
翻译过来就是:这个参数允许将列的数据单位设为字符而不是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
Bug 1488174 UNICODE: ALTER SYSTEM SET NLS_LENGTH_SEMANTICS DOESN'T 进一步测试,在另一个字符集设为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 可以看出,在字符集为单字节的情况下,无论取何值,汉字都是以二个字节的方式存在的.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/256370/viewspace-1025274/
,如需转载,请注明出处,否则将追究法律责任。
alter table "" modify "
创建脚本,修改列设定. 注:Bug-3611750, ora-01450 online rebuild of index fails, 可以在重建索引前指定byte, 10.2.0.5以上已经修复
TAKE EFFECT, 用此语句修改后,实际上不起作用,需要重启才能生效, 但是如果用alter session方式即时生效,不用重启.