SQL Notes Chapter 2
SQL Notes Chapter 2
Datatypes are used to find out what type or kind of data that is given for a particular
column.
Types of datatypes
1. CHAR
2. VARCHAR/VARCHAR2
3. DATE
4. NUMBER
5. LARGE OBJECTS
a. CHARACTER LARGE OBJECTS
b. BINARY LARGE OBJECTS
1. CHAR Datatype
It is used to store the characters.
It accepts the following
‘a-z’, ‘A-Z’, ‘0-9’, Special characters and Alphanumeric characters
(Combination of alphabet and numbers).
We have to write characters within (‘’) single quotes.
SYNTAX: CHAR(SIZE)
Whenever we use char data type we have to mention the size for it.
The maximum size of char data type is 2000ch.
Char datatype follows “Fixed length memory allocation”.
Example: CHAR (10)
D I N G A
Compiler
VARCHAR VARCHAR2
3.DATE
It is used to store the date kind of data.
It will accept oracle-based date formats are
1. ‘DD-MON-YYYY’
Example: ‘14-MAR-2024’
2. ‘DD-MON-YY’
Example: ’14-MAR-24’
Syntax: DATE
4.NUMBER
Number data type is used to accept only the numerical values that is given for a
column.
Syntax: NUMBER (PRECISION, [SCALE])
PRECISION: It is used to determine the total number of digits present in the value.
The range of precision is 1 to 38.
SCALE: It is used to determine the total number of decimal digits present in the value.
The range of scale is from -84 to 127.
Scale is not mandatory and default value of scale is 0.
Example:
Case 1: Without scale value.
NUMBER (6)
9 9 9 9 9 9
The maximum value that we can store here is 9,99,999 and we cannot store more than
9,99,999.
Case 2: When precision is more than scale.
NUMBER (4,2)
9 9 9 9
Syntax: CLOB
Syntax: BLOB