Home > Ask the Oracle Experts > Questions & Answers > CHAR versus VARCHAR2
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

CHAR versus VARCHAR2

Karen Morton EXPERT RESPONSE FROM: Karen Morton

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 09 December 2002
One of our clients is insisting that we change all our CHAR data columns to VARCHAR2 data types. He claims that CHAR is bad for performance. I have never heard this point of view. He's failed to provide any technical reason or a sample script demonstrating the issue. Are there any problems using CHAR? Is it a bad data type to use? Any feedback at all would be extremely helpful to me. A sample script to verify this would be of great help.

>
EXPERT RESPONSE

A CHAR and a VARCHAR2 are stored identically. The difference between the two is that CHAR(n) will always be "n" bytes long and will blank pad to ensure this. Whereas a VARCHAR2(n) will only store the amount of bytes that is actually there. For instance, if you have CHAR(5) and VARCHAR2(5) and insert the word 'CAR' into that column, the CHAR column will contain 'CAR ' and the VARCHAR2 column will contain 'CAR'. Using CHAR on a field with varying length entries can be a real pain due to the search semantics. You'd always have to make sure and trim a CHAR field when doing comparisons. In our 'CAR' example, CHAR(5) <> VARCHAR2(5). In other words, 'CAR ' does not equal 'CAR'.

For a good example of how you can see the differences in performance see Tom Kytes's answer to a similar question. This link will show you how PL/SQL deals with CHAR and VARCHAR2 differently.

In general, I only use CHAR if I'm doing a CHAR(1)....and not because of any real performance reason... I'm just lazy and typing CHAR(1) takes less typing than VARCHAR2(1)! Otherwise, there's not a real reason to use CHAR and more good reasons to use VARCHAR2.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts