---
title: "Exclusive CHAR Vs. VARCHAR in DB2 SQL"
description: "Here explained how DB2 CHAR and VARCHAR stores strings. It's helpful to understand the differences between these two."
url: https://srinimf.com/2022/01/03/exclusive-char-vs-varchar-in-db2-sql/
date: 2022-01-03
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/01/pexels-photo-6540026.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2"]
tags: ["DB2 CHAR Vs VARCHAR"]
type: post
lang: en
---

# Exclusive CHAR Vs. VARCHAR in DB2 SQL

Here’re the differences between CHAR and VARCHAR. You can use these to store strings. For instance, names are one such kind of data.

Related[DB2 SQL: How to Copy Data in one Table to Another Table](https://srinimf.com/2015/03/31/db2-v11-copy-data-one-table-to-another/)

*CHAR Vs VARCHAR*

## CHAR data type

The CHAR data type pads space when the moved string is shorter. Let us say you have created emp_name with CHAR of 20.

```
emp_name CHAR(20)
```

Here, I moved ‘Vani Mohan’ to the emp_name. The first 10 bytes will have actual string, and the next 10 bytes will be spaces.

![Char vs Varchar](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/01/char-vs-varchar.jpg?resize=500%2C500&ssl=1)

## VARCHAR data type

The VARCHAR works the other way round of CHAR. Let us say the emp_name column you defined as VARCHAR(20).

When you move ‘Vani Mohan’ to the emp_name, it stores the string as two parts. One is length, and another part is an actual string.

==> Length (2 bytes) + Actual string

```
When you move 'VANI MOHAN' to emp_name. It occupies internally as 
first 2 bytes is length and rest 10 bytes will be actual length.
```

Related[DB2 DCLGEN All You Need About it](https://srinimf.com/2016/06/30/tricky-db2-question-on-dclgen/)

The VARCHAR doesn’t pad spaces when the string length supplied is shorter.

Related[DB2 SQL Procedure Basics for Mainframe Programmers (1 of 2)](https://srinimf.com/2015/09/24/db2-sql-procedure-basics-for-mainframe-programmers-1-of-2/)

**Performance **

- The maximum for CHAR is 255 bytes
- The VARCHAR’s maximum size [depends on the page size](https://www.bmc.com/blogs/db2-limits/)

The CHAR and VARCHAR improve performance if you use them correctly.

Related posts

- [SQL CAST Function: How to Convert CHAR to VARCHAR](https://srinimf.com/2012/04/24/db2-why-cast-function-needed-2-of-2/)DateApril 24, 2012
- [8 Date Types of Oracle SQL You Need](https://srinimf.com/2016/08/02/8-different-data-types-in-oracle/)DateAugust 2, 2016
- [DB2 Numeric, String, Date, Time Data types](https://srinimf.com/2015/08/17/db2-numeric-string-date-time-data-types/)DateAugust 17, 2015

# Top organic products

For healthy and stylish life style.

[Shop now](https://www.amazon.in/s?k=organic+products&crid=34MJBGHPNWE7F&sprefix=organic+produc%2Caps%2C822&ref=nb_sb_noss_2?tag=srinimf-21)

[Pre-order](https://www.amazon.in/s?k=organic+products&crid=34MJBGHPNWE7F&sprefix=organic+produc%2Caps%2C822&ref=nb_sb_noss_2?tag=srinimf-21)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F01%2F03%2Fexclusive-char-vs-varchar-in-db2-sql%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F01%2Fpexels-photo-6540026.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Exclusive%20CHAR%20Vs.%20VARCHAR%20in%20DB2%20SQL)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/01/03/exclusive-char-vs-varchar-in-db2-sql/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/01/03/exclusive-char-vs-varchar-in-db2-sql/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/01/03/exclusive-char-vs-varchar-in-db2-sql/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/01/03/exclusive-char-vs-varchar-in-db2-sql/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Exclusive%20CHAR%20Vs.%20VARCHAR%20in%20DB2%20SQL&body=https%3A%2F%2Fsrinimf.com%2F2022%2F01%2F03%2Fexclusive-char-vs-varchar-in-db2-sql%2F&share=email)
-

### Like this:

Like Loading…
