Does it make difference if I allocate number(2,0) or number(4,0) if I will only store numbers from 1 to 20

StackOverflow https://stackoverflow.com/questions/23636601

Pergunta

The question is about tablespace/file usage. If I had one table with column x number(2,0) and another, with column y number(4,0). Would the second table take up more space? Would there be more memory used during operations on that table?

Although

select * from user_tab_columns where table_name...

returns DATA_LENGTH = 22 for both columns. Does it mean that table will take same space? Or space will be determined by data itself and Oracle only monitors what kind numbers you store?

Foi útil?

Solução

The amount of memory will depend solely on the data you store in this case. You won't use any more memory declaring the column number(4,0), you won't save any declaring the column number(2,0). You can use the vsize function to see the actual amount of space required to store any particular piece of information. In this case, you'll need 2 bytes for each number regardless of the data type which you can see in this SQL Fiddle.

Of course, if you declare the column number(4,0), you should assume that someone will store values larger than 99 in that table so you'd need to ensure that your code can handle that appropriately.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top