Friday, April 23, 2010

CHAR Datatype in Oracle

The CHAR datatype stores fixed-length character strings. When you create a table with a CHAR column, you must specify a string length (in bytes or characters) between 1 and 2000 bytes for the CHAR column width. The default is 1 byte. Fixed length character data of length size bytes. This should be used for fixed length data. Such as codes A100, B102...

Oracle then guarantees that:


When you insert or update a row in the table, the value for the CHAR column has the fixed length.

If you give a shorter value, then the value is blank-padded to the fixed length.

If a value is too large, Oracle Database returns an error.

Oracle Database compares CHAR values using blank-padded comparison semantics.

usage: variablename char(size)
eg:
 
user_id char(8)