Oracle 1Z0-071, Character Data Types

Objective: Using DDL Statements to Create and Manage Tables, Describe data types that are available for columns.

Char

  • Fixed length
  • Stored 1 character as 1 byte

NChar

  • Fixed Length
  • Stores 1 character as 2 bytes
  • UTF-16 encoding
  • Typical outside of America

In the case of NChar or Char, if you designate a column as 10 characters it will allocate 10 characters to memory regardless of your value being 2, 4, or 7 characters. Therefore, it is not as efficient as Varchar.

Char and NChar are also not backwards compatible. For these two reasons Oracle recommends we avoid using Char data types, and instead opt for the Varchar2 datatype covered in another article.

There are only two use cases where you could consider using Char data types.

Case 1: EDI Electronic Data Interchange fixed length

In the case of EDI, we might consider Char for it’s forced padding. This would allow us to skip the use of lpad and rpad functions to ensure field length requirements, however this also would be substantially less efficient and should be avoided.

Case 2: Null and empty string recognition

In a case where explicit recognition of null or empty string might be another case. In this case, inserting a null into a Char column will not trigger Char’s default padding behavior whereas inserting a empty string will.

If you have these two use cases you will be better served by utilizing the Varchar2 data type. Varchar2 can handle each of these cases and is more efficient.

Check out Crash Course Oracle 1Z0-071 Subqueries

Good Luck!