作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一个数字列来作为我正在处理的内容的指示器,但我不希望它在每个记录中占用超过一个字节。如果我使用 NUMBER(1),这能满足我的要求吗?
最佳答案
NUMBER(1)
列将占用存储 1 位数字所需的空间。这可能超过 1 个字节(负数需要 3 个字节,0 需要 1 个字节,数字 1-9 需要 2 个字节)
SQL> create table foo( col1 number(1) );
Table created.
SQL> insert into foo values( 1 );
1 row created.
SQL> insert into foo values( 9 );
1 row created.
SQL> insert into foo values( -7 );
1 row created.
SQL> select vsize(col1), col1 from foo;
VSIZE(COL1) COL1
----------- ----------
2 1
2 9
3 -7
另一方面,具有 VARCHAR2(1 BYTE)
列的表每行最多使用 1 个字节的存储空间
SQL> create table bar( col1 varchar2(1) );
Table created.
SQL> insert into bar values( 'Y' );
1 row created.
SQL> insert into bar values( 'N' );
1 row created.
SQL> select vsize(col1), col1 from bar;
VSIZE(COL1) C
----------- -
1 Y
1 N
关于甲骨文11g : Can I create a number column that stores only 1 byte?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9334052/
我是一名优秀的程序员,十分优秀!