You are here: Foswiki>Service Web>Varchar2VsChar (11 Nov 2016, MezianeKettou)Edit Attach
-- MezianeKettou - 11 Nov 2016

Use VARCHAR2 instead of CHAR.

Use CHAR only for columns with fixed length like a Postcode, an ISBN and the like.

Also to store boolean values always use VARCHAR2 instead of CHAR(1). Problems have been reported for Databases using UTF-8, as 3 Bytes were returned for Columns declared and comprehensibly excepected to return just 1 Byte.

CREATE TABLE test_table (
char_col CHAR(10),
varchar2_col VARCHAR2(10));


insert into test_table values ('A', 'A');

select length(char_col), length(varchar2_col) from test_table;
LENGTH(CHAR_COL) LENGTH(VARCHAR2_COL)
10 1
Actually Oracle stores always 10 bytes in the Database for char_col. With other words: a CHAR(nn) column is always right padded with spaces to fill its max length.

select '"'||char_col||'"' , '"'||varchar2_col||'"' from test_table;
"CHAR_COL" "VARCHAR2_COL"
"A         "
"A"
Topic revision: r2 - 11 Nov 2016, MezianeKettou
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback