- VARCHAR2 is used to store variable-length character strings.
- When you define VARCHAR2(n), it can store up to n characters, but doesn’t pad extra spaces.
- If you insert fewer characters, no extra spaces are added.
- Maximum size of VARCHAR2 is 4000 bytes in SQL and up to 32767 bytes in PL/SQL.
- VARCHAR2 is best for data that varies in length, like names, emails, or addresses.
- Example: If you define VARCHAR2(10) and insert "ABC", Oracle stores it as "ABC" (no extra spaces).
- It saves storage space compared to CHAR for variable-length data.
- Comparisons consider the exact value (trailing spaces are not added).
- VARCHAR2 may have slightly higher processing overhead than CHAR for fixed-length data.
- It is defined by specifying the column name and maximum length, for example, a column of length 50.
Example:
1.
VARCHAR2(5) →
Input: A →
Stored as: A
2.
VARCHAR2(5) →
Input: AB →
Stored as: AB
3.
VARCHAR2(5) →
Input: #@! →
Stored as: #@!
4.
VARCHAR2(4) →
Input: เค (Hindi) →
Stored as: เค
5.
VARCHAR2(6) →
Input: 123 →
Stored as: 123
6.
VARCHAR2(3) →
Input: ๐ →
Stored as: ๐
7.
VARCHAR2(8) →
Input: ู
ุฑุญุจุง (Arabic) →
Stored as: ู
ุฑุญุจุง
8.
VARCHAR2(10) →
Input: HELLO → Stored
as: HELLO
9.
VARCHAR2(4) →
Input: ฯ
→ Stored as: ฯ
10.
VARCHAR2(7) →
Input: ใในใ (Japanese) →
Stored as: ใในใ
Key differences from CHAR:
·
VARCHAR2 does
not add blank spaces.
· Works for letters, numbers, symbols, emojis, and other languages.
· Storage depends on actual length of the input.
If you want, I can also make a ready-to-use INSERT list for these 10 examples.