đ SQL Data Types: NUMBER, CHAR, VARCHAR2, DATE, TIMESTAMP
SQL data types define what kind of data a column can hold. Below are common data types with Bangladeshi examples and real-life use cases.
đĸ 1️⃣ NUMBER
Syntax: NUMBER(p, s)
Explanation: Stores numeric values.
p
= precision (total digits)s
= scale (digits after decimal)
salary NUMBER(8, 2) -- Example: 50000.00
Use Case: Employee salary, product price, tax, etc.
đ¤ 2️⃣ CHAR
Syntax: CHAR(n)
Explanation: Fixed-length string. Always takes up n
characters, padding with spaces if needed.
gender CHAR(1) -- Example: 'M' or 'F'
Use Case: Gender, grade, status flags.
✍️ 3️⃣ VARCHAR2
Syntax: VARCHAR2(n)
Explanation: Variable-length string. Efficient for names, emails, and addresses.
name VARCHAR2(100) -- Example: 'Nasrin Akter'
Use Case: Names, emails, project titles.
đ 4️⃣ DATE
Stores: Date and time (up to seconds)
hire_date DATE -- Example: '2023-06-15'
Use Case: Birth date, hire date, order date.
⏱️ 5️⃣ TIMESTAMP
Stores: Date and time with fractional seconds (more precision than DATE)
created_at TIMESTAMP -- Example: '2023-07-26 14:45:23.540'
Use Case: Logging exact event time, audit trails.
đ Example Table: employees
CREATE TABLE employees (
id NUMBER PRIMARY KEY,
name VARCHAR2(100),
gender CHAR(1),
salary NUMBER(8, 2),
hire_date DATE,
created_at TIMESTAMP
);
đ§ Sample Row:
INSERT INTO employees VALUES (
1,
'Rafiul Islam',
'M',
55000.00,
TO_DATE('2022-01-10','YYYY-MM-DD'),
SYSTIMESTAMP
);
Use
NUMBER
for numeric values, CHAR
for fixed small strings, VARCHAR2
for variable text, DATE
for date/time, and TIMESTAMP
for precise logging.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ