Oracle 11g: can I create a column of numbers that only stores 1 byte?

I need a column of numbers that will serve as an indicator of what I'm working on, but I don't want it to take more than one byte per record. If I use NUMBER (1), will this satisfy my requirement?

+6
source share
1 answer

Column A NUMBER(1) will take up as much space as needed to store a 1-digit number. This will probably be more than 1 byte (negative numbers require 3 bytes, 0 - 1 byte, digits 1-9 - 2 bytes)

 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 

A table with a VARCHAR2(1 BYTE) column VARCHAR2(1 BYTE) , on the other hand, will use no more than 1 byte per storage row

 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 
+15
source

Source: https://habr.com/ru/post/908740/


All Articles