日期:2014-05-16 浏览次数:20588 次
1.char
char是定长字符型,内部代码是:96,最多可以存储2000个字节,其中在char字符变量中,字节长度无法满足申请长度的则自动以空格变量补足,空格变量ASCII码为32;
2.varchar2
varchar2是变长字符型,内部代码是:1,最多可以存储4000个字符
实验如下:
?
SYS@huiche> create table test_char (char_col char(10), varchar_col varchar2(10));
表已创建。
SYS@huiche>insert into test_char values ('abc','abc');
已创建 1 行。
SYS@huiche>insert into test_char values ('testchar12','testchar12');
已创建 1 行。
SYS@huiche>insert into test_char values ('中国','中国');
已创建 1 行。
SYS@huiche>commit;
提交完成。
SYS@huiche>select dbms_rowid.rowid_object(rowid) object_id, dbms_rowid.rowid_relative_fno(rowid) file_id,
2 dbms_rowid.rowid_block_number(rowid) block_id ,dbms_rowid.rowid_row_number(rowid) num from test_char;
OBJECT_ID FILE_ID BLOCK_ID NUM
---------- ---------- ---------- ----------
63183 1 86858 0
63183 1 86858 1
63183 1 86858 2
SYS@huiche>alter system dump datafile 1 block 86858;
系统已更改。
SYS@huiche>
?其中dump文件内容为:
?
data_block_dump,data header at 0x524845c
===============
tsiz: 0x1fa0
hsiz: 0x18
pbl: 0x0524845c
bdba: 0x0041534a
76543210
flag=--------
ntab=1
nrow=3
frre=-1
fsbo=0x18
fseo=0x1f60
avsp=0x1f48
tosp=0x1f48
0xe:pti[0] nrow=3 offs=0
0x12:pri[0] offs=0x1f8e
0x14:pri[1] offs=0x1f75
0x16:pri[2] offs=0x1f60
block_row_dump:
tab 0, row 0, @0x1f8e
tl: 18 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [10] 61 62 63 20 20 20 20 20 20 20
col 1: [ 3] 61 62 63
tab 0, row 1, @0x1f75
tl: 25 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [10] 74 65 73 74 63 68 61 72 31 32
col 1: [10] 74 65 73 74 63 68 61 72 31 32
tab 0, row 2, @0x1f60
tl: 21 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [10] e4 b8 ad e5 9b bd 20 20 20 20
col 1: [ 6] e4 b8 ad e5 9b bd
end_of_block_dump
End dump data blocks tsn: 0 file#: 1 minblk 86858 maxblk 86858
?
?其中也可以用dump函数:
SYS@huiche>select char_col,dump(char_col,16) from test_char; CHAR_COL DUMP(CHAR_COL,16) -------------------- -------------------------------------------------- abc Typ=96 Len=10: 61,62,63,20,20,20,20,20,20,20 testchar12 Typ=96 Len=10: 74,65,73,74,63,68,61,72,31,32 中国 Typ=96 Len=10: e4,b8,ad,e5,9b,bd,20,20,20,20 SYS@huiche>select varchar_col,dump(varchar_col,16) from test_char; VARCHAR_COL DUMP(VARCHAR_COL,16) -------------------- -------------------------------------------------- abc Typ=1 Len=3: 61,62,63 testchar12 Typ=1 Len=10: 74,65,73,74,63,68,61,72,31,32 中国 Typ=1 Len=6: e4,b8,ad,e5,9b,bd SYS@huiche>SYS@huiche>select * from nls_database_parameters where parameter like '%CHARACTERSET%'; PARAMETER VALUE ------------------------ ---------------------------- NLS_CHARACTERSET AL32UTF8 NLS_NCHAR_CHARACTERSET UTF8
?
?根据dump文件和dump函数的比较可以说明:字符类型在oracle数据库底层是以16进制的ASCII码存储,汉字根据数据库字符集不同,在GBK字符集中占用2字节,在UTF8字符集中占用3个字节。