0

I have been very interesting to know that when we declare a variable such as varchar2(10), some fixed amount of memory will be allocated. We can estimate it by printing/displaying output. It have some empty strings in that length where there are no characters.

Interestingly while for varchar2 it just displays the string that we entered/stored in the database earlier without having empty strings.

My question is how these are stored, is it already fixed upto the given length or Is memory allocated to the length we have declared or only for the string that we store in it.

Example: If I declare varchar2(10) and store string "Hello" then will the memory allocated to all the 10 characters as declared or allocated only to the 5 letter string I have stored.

Can anyone one please explain.

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    MySQL or SQL Server? They are completely different databases and will therefore warrant completely different answers. – Dale K Sep 13 '19 at 01:29
  • no such thing as varchar2 in sql server. – SMor Sep 13 '19 at 01:30
  • Or even Oracle - since that seems to be where `varchar2` exists. – Dale K Sep 13 '19 at 01:32
  • 1
    *when we declare a variable such as varchar(10), some fixed amount of memory will be allocated.* is it a `char`? this question better of go to [DBA Stackexchange](https://dba.stackexchange.com/), really. – Bagus Tesa Sep 13 '19 at 01:32
  • I've removed the RDBMS tags since they are incorrect - please add the correct tag back or delete the question and ask at DBA Stackexchange. – Dale K Sep 13 '19 at 01:36

0 Answers0