最近使用oracle数据类型varchar2,发现使用下面的update 语句在不同字符集下结果不一致
update userhistory set value = 'What'||chr(140)||'Are'||chr(130)||'you'||chr(20)||chr(10) where id=3;
commit;
 在英文oracle下面看二进制和set的值一样
在日文oracle下面就不一样了脚本是在PL/SQL Developer里测试的
附:
英文的NLS
NLS_CALENDAR GREGORIAN 
NLS_CHARACTERSET WE8ISO8859P1 
NLS_COMP BINARY 
NLS_CURRENCY $ 
NLS_DATE_FORMAT DD-MON-RR 
NLS_DATE_LANGUAGE AMERICAN 
NLS_DUAL_CURRENCY $ 
NLS_ISO_CURRENCY AMERICA 
NLS_LANGUAGE AMERICAN 
NLS_NCHAR_CHARACTERSET WE8ISO8859P1 
NLS_NUMERIC_CHARACTERS ., 
NLS_RDBMS_VERSION 8.1.7.0.0 
NLS_SORT BINARY 
NLS_TERRITORY AMERICA 
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM 
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZH:TZM 
NLS_TIME_FORMAT HH.MI.SSXFF AM 
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZH:TZM 
日文的NLS
NLS_CALENDAR GREGORIAN 
NLS_CHARACTERSET JA16SJIS 
NLS_COMP BINARY 
NLS_CURRENCY $ 
NLS_DATE_FORMAT DD-MON-RR 
NLS_DATE_LANGUAGE AMERICAN 
NLS_DUAL_CURRENCY $ 
NLS_ISO_CURRENCY AMERICA 
NLS_LANGUAGE AMERICAN 
NLS_NCHAR_CHARACTERSET JA16SJIS 
NLS_NUMERIC_CHARACTERS ., 
NLS_RDBMS_VERSION 8.1.7.0.0 
NLS_SORT BINARY 
NLS_TERRITORY AMERICA 
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM 
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZH:TZM 
NLS_TIME_FORMAT HH.MI.SSXFF AM 
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZH:TZM

解决方案 »

  1.   

    好像是255
    你用long吧,这个是2G,绝对够用
      

  2.   

    类型是不能修改的,现在问题就是在日文oracle下向里面插入二进制(大于127)字符的时候就被截取了一样,只是像搞清楚原因,在晚上查了查,没查到
      

  3.   

    看數据庫字符集,utf的一個字占三個,zhs的占2個,ascii的占一個!
      

  4.   

    4000字节
    不过我不知道能否将long转换成varchar2。问题很初级
      

  5.   

    是客户端字符集与服务器字符集不一致的问题,如果你想更明白一些,参见:http://www.eygle.com/special/NLS_CHARACTER_SET_01.htm
    |
    http://www.eygle.com/special/NLS_CHARACTER_SET_07.htm
      

  6.   

    pl/sql user's guide中的说明:
    VARCHAR2
    You use the VARCHAR2 datatype to store variable-length character data. How the data is represented internally depends on the database character set. The VARCHAR2 datatype takes a required parameter that specifies a maximum size up to 32767 bytes. The syntax follows:VARCHAR2(maximum_size [CHAR | BYTE])
    You cannot use a symbolic constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.Small VARCHAR2 variables are optimized for performance, and larger ones are optimized for efficient memory use. The cutoff point is 2000 bytes. For a VARCHAR2 that is 2000 bytes or longer, PL/SQL dynamically allocates only enough memory to hold the actual value. For a VARCHAR2 variable that is shorter than 2000 bytes, PL/SQL preallocates the full declared length of the variable. For example, if you assign the same 500-byte value to a VARCHAR2(2000 BYTE) variable and to a VARCHAR2(1999 BYTE) variable, the former takes up 500 bytes and the latter takes up 1999 bytes.If you specify the maximum size in bytes rather than characters, a VARCHAR2(n) variable might be too small to hold n multibyte characters. To avoid this possibility, use the notation VARCHAR2(n CHAR)so that the variable can hold n characters in the database character set, even if some of those characters contain multiple bytes. When you specify the length in characters, the upper limit is still 32767 bytes. So for double-byte and multibyte character sets, you can only specify 1/2 or 1/3 as many characters as with a single-byte character set.Although PL/SQL character variables can be relatively long, the maximum width of a VARCHAR2 database column is 4000 bytes. So, you cannot insert VARCHAR2 values longer than 4000 bytes into a VARCHAR2 database column.You can insert any VARCHAR2(n) value into a LONG database column because the maximum width of a LONG column is 2**31 bytes. However, you cannot retrieve a value longer than 32767 bytes from a LONG column into a VARCHAR2(n) variable.When you do not use the CHAR or BYTE qualifiers, the default is determined by the setting of the NLS_LENGTH_SEMANTICS initialization parameter. When a PL/SQL procedure is compiled, the setting of this parameter is recorded, so that the same setting is used when the procedure is recompiled after being invalidated.
      

  7.   

    Although PL/SQL character variables can be relatively long, the maximum width of a VARCHAR2 database column is 4000 bytes. So, you cannot insert VARCHAR2 values longer than 4000 bytes into a VARCHAR2 database column.
    我想这段足以给楼主解惑
      

  8.   

    4000个字节
    如果太大可以考虑blob 或者long