CHAR Data Type

1.     CHAR is used to store fixed-length character strings.

2.     When you define CHAR with a length, it always stores exactly that many characters.

3.     If you insert fewer characters, Oracle adds spaces to fill the remaining length.

4.     Maximum size of CHAR is 2000 bytes.

5.     CHAR is best for data that has a constant length, like gender codes or country codes.

6.     For example, if you define CHAR with length 5 and insert "ABC", Oracle will store it as "ABC ".

7.     It uses blank-padding, not variable storage.

8.     Comparisons ignore trailing spaces.

9.     CHAR uses less processing overhead than VARCHAR2.

10.  It is defined by specifying the column name and length, for example, a column of length 10.

 

Examples 

1.     CHAR(5) → Input: ABCDE → Stored as: 'ABCDE' ✅ (no extra spaces)

2.     CHAR(5) → Input: AB → Stored as: 'AB '

3.     CHAR(3) → Input: 😊 → Stored as: '😊 '

4.     CHAR(4) → Input: π → Stored as: 'π '

5.     CHAR(6) → Input: 123456 → Stored as: '123456' ✅ (no extra spaces)

6.     CHAR(8) → Input: HELLO → Stored as: 'HELLO '

7.     CHAR(4) → Input: IN → Stored as: 'IN '

8.     CHAR(7) → Input: テスト → Stored as: 'テスト '

9.     CHAR(2) → Input: Y → Stored as: 'Y '

10.  CHAR(5) → Input: #@!$% → Stored as: '#@!$%' ✅ (no extra spaces)

Key idea:

·        If the input length = CHAR(n) → no blank spaces added.

·        If input length < CHAR(n) → Oracle pads with blanks on the right.


No comments:

Post a Comment