gpt4 book ai didi

甲骨文11g : Can I create a number column that stores only 1 byte?

转载 作者:行者123 更新时间:2023-12-02 02:01:37 24 4
gpt4 key购买 nike

我需要一个数字列来作为我正在处理的内容的指示器,但我不希望它在每个记录中占用超过一个字节。如果我使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com