SQL Data Types specify the type of data that can be stored in a table column. They help ensure data accuracy and efficient storage.
1. Character (String) Data Types
| Data Type | Description |
|---|
| CHAR(n) | Fixed-length character string |
| VARCHAR(n) | Variable-length character string |
| VARCHAR2(n) | Oracle variable-length character string |
| NCHAR(n) | Fixed-length Unicode character string |
| NVARCHAR2(n) | Variable-length Unicode character string |
| LONG | Variable-length character data (Oracle) |
Example
Name VARCHAR(50),
Gender CHAR(1)
2. Numeric Data Types
| Data Type | Description |
|---|
| NUMBER(p,s) | Stores numeric values with precision and scale |
| INT / INTEGER | Stores whole numbers |
| SMALLINT | Small-range integer |
| DECIMAL(p,s) | Fixed-point number |
| FLOAT | Floating-point number |
| REAL | Real number |
Example
StudentID INT,
Marks NUMBER(5,2)
3. Date and Time Data Types
| Data Type | Description |
|---|
| DATE | Stores date and time |
| TIMESTAMP | Stores date and time with fractional seconds |
| INTERVAL | Stores a period of time |
Example
DOB DATE,
CreatedOn TIMESTAMP
4. Binary Data Types
| Data Type | Description |
|---|
| RAW(n) | Stores binary data |
| LONG RAW | Stores large binary data |
Example
Photo RAW(2000)
5. Large Object (LOB) Data Types
| Data Type | Description |
|---|
| CLOB | Character Large Object |
| NCLOB | Unicode Character Large Object |
| BLOB | Binary Large Object |
| BFILE | Binary file stored outside the database |
Example
Document CLOB,
Image BLOB
Oracle SQL Data Types Summary
| Category | Data Types |
|---|
| Character | CHAR, VARCHAR2, NCHAR, NVARCHAR2, LONG |
| Numeric | NUMBER, INT, INTEGER, FLOAT, DECIMAL |
| Date/Time | DATE, TIMESTAMP, INTERVAL |
| Binary | RAW, LONG RAW |
| LOB | CLOB, NCLOB, BLOB, BFILE |
Example Table Using Different Data Types
CREATE TABLE Student (
StudentID NUMBER(5),
Name VARCHAR2(50),
Gender CHAR(1),
DOB DATE,
Marks NUMBER(5,2),
Photo BLOB
);
Output Structure
| Column | Data Type |
|---|
| StudentID | NUMBER(5) |
| Name | VARCHAR2(50) |
| Gender | CHAR(1) |
| DOB | DATE |
| Marks | NUMBER(5,2) |
| Photo | BLOB |
In short: SQL data types define what kind of values (text, numbers, dates, images, etc.) can be stored in a database column.