標籤:
首先介紹下 單一位元組字元集 和 多位元組字元集
2.2字元編碼方案
2.2.1 單位元組編碼
(1)單位元組7位字元集,可以定義128個字元,最常用的字元集為 US7ASCII
(2)單位元組8位字元集,可以定義256個字元,適合於歐洲大部分國家
例如:WE8ISO8859P1(西歐、8位、ISO標準8859P1編碼 )
2.2.2 多位元組編碼
(1)變長多位元組編碼
某些字元用一個位元組表示,其它字元用兩個或多個字元表示,變長多位元組編碼常用於對亞洲語言的支援, 例如日語、漢語、印地語等
例如:AL32UTF8(其中AL代表ALL,指適用於所有語言)、 zhs16cgb231280
(2)定長多位元組編碼
每一個字元都使用固定長度位元組的編碼方案,目前oracle唯一支援的定長多位元組編碼是AF16UTF16,也是僅用於國家字元集
2.2.3 unicode 編碼
Unicode 是一個涵蓋了目前全世界使用的所有已知字元的單一編碼方案,也就是說Unicode為每一個字元提供唯一的編碼。UTF-16是unicode的16位編碼方式,是一種定長多位元組編碼,用2個位元組表示一個unicode字元,AF16UTF16是UTF-16編碼字元集。
UTF-8 是unicode的8位編碼方式,是一種變長多位元組編碼,這種編碼可以用1、2、3個位元組表示一個unicode字元,AL32UTF8,UTF8、UTFE是UTF-8編碼字元集
LENGTH
Syntax
length::=
Description of the illustration length.gif
Purpose
The LENGTH functions return the length of char. LENGTH calculates length using characters as defined by the input character set. LENGTHB uses bytes instead of characters. LENGTHC uses Unicode complete characters. LENGTH2 uses UCS2 code points. LENGTH4 uses UCS4 code points.
char can be any of the data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The exceptions are LENGTHC, LENGTH2, and LENGTH4, which do not allow char to be a CLOB or NCLOB. The return value is of data type NUMBER. If char has data type CHAR, then the length includes all trailing blanks. If char is null, then this function returns null.
Restriction on LENGTHB The LENGTHB function is supported for single-byte LOBs only. It cannot be used with CLOB and NCLOB data in a multibyte character set.
Examples
The following example uses the LENGTH function using a single-byte database character set:
SELECT LENGTH(‘CANDIDE‘) "Length in characters" FROM DUAL;Length in characters-------------------- 7
The next example assumes a double-byte database character set.
SELECT LENGTHB (‘CANDIDE‘) "Length in bytes" FROM DUAL; Length in bytes--------------- 14
oracle官方文檔- length篇