What is the major difference between Varchar2 and char

前端 未结 7 743
独厮守ぢ
独厮守ぢ 2020-11-22 14:33

Creating Table:

CREATE TABLE test (
charcol    CHAR(10),
varcharcol VARCHAR2(10));

SELECT LENGTH(charcol), LENGTH(varcharcol) FROM test;
         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 15:12

    CHAR

    CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.

    VARCHAR2

    VARCHAR2 is used to store variable length character strings. The string value's length will be stored on disk with the value itself.

    And

    At what times we use both?
    

    Its all depend upon your requirement.

提交回复
热议问题