What is the major difference between Varchar2 and char

前端 未结 7 715
独厮守ぢ
独厮守ぢ 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:00

    CHAR is used for storing fix length character strings. It will waste a lot of disk space if this type is used to store varibale length strings.

    VARCHAR2 is used to store variable length character strings.

    At what times we use both?

    This may vary and depend on your requirement.

    EDIT:-

    Lets understand this with an example, If you have an student name column with size 10; sname CHAR(10) and If a column value 'RAMA' is inserted, 6 empty spaces will be inserted to the right of the value. If this was a VARCHAR column; sname VARCHAR2(10). Then Varchar will take 4 spaces out of 10 possible and free the next 6 for other usage.

提交回复
热议问题