HomePagev2 Forums SQL Discussions CHAR and VARCHAR2 datatypes Reply To: CHAR and VARCHAR2 datatypes

  • Naimisha Chekka

    Member
    September 13, 2020 at 4:56 am

    The difference is that CHAR(n) will ALWAYS be n bytes long. If the string length is <n, it will be blank padded upon insert to ensure a length of n. A VARCHAR2(n) on the other hand will be 1 to n bytes long. A shorter string stored as VARCHAR2 will NOT be blank padded.

     
    <p style=”text-align: right;”>For example, suppose you store the string ‘ORATABLE’ in a CHAR(20) field and a VARCHAR2(20) field. The CHAR field will use 22 bytes (2 bytes for leading length). The VARCHAR2 field will use 10 bytes only (8 for the string, 2 bytes for leading length).</p>
    I hope your doubt is clear…