Datatype in Oracle SQL

Datatype in Oracle SQL

A Beginner's Guide to Datatypes in Oracle SQL

DataType

Data type is used to specify the type of data that will be stored in a particular memory location.

Types of Data Type

  1. CHAR

  2. VARCHAR/ VARCHAR2

  3. NUMBER

  4. DATE

  5. LARGE OBJECT

    1. CHARACTER LARGE OBJECT

    2. BINARY LARGE OBJECT


CHAR

  1. CHAR datatype can accept ‘A - Z’, ‘a - z’, ‘0 - 9’, ‘special characters’ as well as ‘ Alphanumerics’.

  2. Characters must always be enclosed within single quotes

    Syntax: CHAR (SIZE)

  3. Whenever we use CHAR datatype we must mention it’s size.

SIZE

  1. It is used to specify number of characters it can store

  2. The maximum no. of characters it can store is 2000 characters.

  3. CHAR datatype follows fixed length memory allocation.


VARCHAR

  1. VARCHAR datatype can accept ‘A - Z’, ‘a - z’, ‘0 - 9’, ‘special characters’ as well as ‘ Alphanumerics’.

  2. Characters must always be enclosed within single quotes

    Syntax: VARCHAR (SIZE)

  3. Whenever we use VARCHAR datatype we must mention it’s size.

SIZE

  1. It is used to specify number of characters it can store

  2. The maximum no. of characters it can store is 2000 characters.

  3. CHAR datatype follows variable length memory allocation.

VARCHAR2

  1. It is an updated version of VARCHAR2 datatype

  2. It can store up to 4000 characters

Syntax: VARCHAR (SIZE)

💡
Whenever we use VARCHAR datatype, by default it is converted into VARCHAR2 datatype

DATE

  1. It is used to store the date in a particular format.

  2. It use ORACLE specified format

    1. ‘DD-MON-YYYY’

    2. ‘DD-MON-YY’

Syntax: DATE

  1. e.g. ‘28-AUG-2024’, ‘28-AUG-24’

NUMBER

  1. It is used to store the numeric value

    Syntax: NUMBER(PRECISION, [SCALE])

  2. PRECISION:

    It is used to specify the number of digits to store the integer values

  3. SCALE:

    It is used to specify the number of digits to store decimal values within the precision

    The default value of scale is 0

    SCALE is optional


LARGE OBJECT

  1. CHARACTER LARGE OBJECT:

    It is used to store characters upto 4GB of size

  2. BINARY LARGE OBJECT:

    It is used to store binary values of images, documents, etc, upto $GB of size.