数据库 字段 数据类型的疑问?

wbdx 2005-09-29 04:33:23

某字段作为标记

可以 VARCHAR(1),也可以NUMBER(1)

1。哪一种更加节省空间,效率最高?
2。选择的理由和依据是什么?
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobfang 2005-09-30
  • 打赏
  • 举报
回复
char(1)并且not null是最省空间的。可以做这样的测试:
create table t_test1(
col3 char(1) not null,
col4 char(1) not null,
col5 char(1) not null,
col6 char(1) not null,
col7 char(1) not null,
col8 char(1) not null,
col9 char(1) not null
)
/
create table t_test2(
col3 number(1) not null,
col4 number(1) not null,
col5 number(1) not null,
col6 number(1) not null,
col7 number(1) not null,
col8 number(1) not null,
col9 number(1) not null
)
/

insert into t_test1 select '1','1','1','1','1','1','1' from all_tab_columns order by table_name,column_id;
insert into t_test2 select 1,1,1,1,1,1,1 from all_tab_columns order by table_name,column_id;
commit;
insert into t_test1 select * from t_test1;
insert into t_test1 select * from t_test1;
commit;
insert into t_test2 select * from t_test2;
insert into t_test2 select * from t_test2;
commit;
analyze table t_test1 compute statistics;
analyze table t_test2 compute statistics;
select segment_name,bytes from user_segments where segment_name like 'T_TEST%';
select table_name,NUM_ROWS,BLOCKS,AVG_ROW_LEN from user_tables where table_name like 'T_TEST%';
wbdx 2005-09-29
  • 打赏
  • 举报
回复
to bobfang(匆匆过客)

NUMBER(1) 有什么不好???
loveme820 2005-09-29
  • 打赏
  • 举报
回复
number(1),众所周知,数字型查询速度快,占用空间小。
bobfang 2005-09-29
  • 打赏
  • 举报
回复
只是做为标记用,可以用char(1)
xmankevin1980xman 2005-09-29
  • 打赏
  • 举报
回复
number(1)高些,也节省空间。首先,比如VARCHAR(4)你输入1个字符,剩下的它用空格补足。而NUMBER就没此种情况.

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧