EnterpriseDB: CHAR Data Type
Oracle Tips by Burleson Consulting
EnterpriseDB also supports a CHAR data type. CHAR is a fixed length
data type. If you don't specify a size, it defaults to 1.
fixed length data type always uses all of its declared length. If
you declare a CHAR(50) and assign it a value, it will be padded to
50 characters with spaces. A VARCHAR2(50) does not pad. I don't
often. VARCHAR2 is much more useful to me as it only requires
storage for characters that are actually used.
declare a 50-character CHAR
you would simply enter the variable name followed by CHAR(50). This
variable or column would pad to 50 spaces when you add any data,
regardless of the data's size.
example, if I declare a variable:
variable name is v_data, the data type is CHAR and the declared
length is 50. The actual length stored is 0 characters because the
variable is null. If we assign it a value:
v_data := 'LEWIS';
gave the variable v_data that value of LEWIS. LEWIS is 5 characters
but our variable now holds 50 characters: 5 characters for LEWIS
and 45 spaces. If v_data had been a VARCHAR2(50), its length would
only be 5.
only benefit of a CHAR
VARCHAR2 is that you always know exactly how long a CHAR column is
going to be. Either it will be NULL or it will be its declared
length. A VARCHAR2 will always either be NULL or it will be some
length less than or equal to its max length.
Synonyms for CHAR are:
Oracle, a CLOB data type is used to store very large text
documents. In Oracle 10g, on a 64-bit machine, a CLOB can store 128
terabytes of data. EnterpriseDB does not support the CLOB data type
directly. A CLOB declaration is transformed to the TEXT data type.
A TEXT field can be up to a gigabyte in size. TEXT works like a
VARCHAR2 but without the declared max size.
Synonyms for CLOB are:
were to create a table with the text data types that we have
discussed, the syntax would look like this:
CREATE TABLE text_table (
that we have a table, we can insert into it:
INSERT INTO text_table (name, address, comments)
VALUES ('Lewis', 'New Orleans', 'My Name is Lewis and My address
is New Orleans.');
If we selected the data back out from the table:
SELECT name, address, comments
I can use EnterpriseDB PSQL (which I spoke about in Chapter 2) to
run these commands.
edb=# CREATE TABLE text_table (
edb(# name VARCHAR2(50),
edb(# address CHAR(50),
edb(# comments CLOB
edb=# INSERT INTO text_table (name, address, comments)
edb-# VALUES ('Lewis', 'New Orleans', 'My Name is Lewis and My
address is New
INSERT 0 1
edb=# SELECT name, address, comments
edb-# FROM text_table;
name | address |
| New Orleans | My Name is Lewis and My address
is New Orleans.
I will use PSQL to run commands for the remainder of this chapter.
is an excerpt from the book "EnterpriseDB:
The Definitive Reference" by Rampant TechPress.