What is difference between CHAR and VARCHAR2?What is the
maximum SIZE allowed for each type?

Answer Posted / esakkiraja

CHAR
-----

SQL> CREATE TABLE char_test (col1 CHAR(10));

Table created.

SQL> INSERT INTO char_test VALUES ('qwerty');

1 row created.

SQL> SELECT col1, length(col1), dump(col1) "ASCII Dump"
FROM char_test;

COL1 LENGTH(COL1) ASCII Dump
---------- ------------ ------------------------------------
------------------------
qwerty 10 Typ=96 Len=10:
113,119,101,114,116,121,32,32,32,32


VARCHAR
-------

SQL> CREATE TABLE varchar_test (col1 VARCHAR2(10));

Table created.

SQL> INSERT INTO varchar_test VALUES ('qwerty');

1 row created.

SQL> SELECT col1, length(col1), dump(col1) "ASCII Dump"
FROM varchar_test;

COL1 LENGTH(COL1) ASCII Dump
---------- ------------ ------------------------------------
------------------------
qwerty 6 Typ=1 Len=6: 113,119,101,114,116,121


VARCAHR2
----------

SQL> CREATE TABLE varchar2_test (col1 VARCHAR2(10));

Table created.

SQL> INSERT INTO varchar2_test VALUES ('qwerty');

1 row created.

SQL> SELECT col1, length(col1), dump(col1) "ASCII Dump"
FROM varchar2_test;

COL1 LENGTH(COL1) ASCII Dump
---------- ------------ ------------------------------------
------------------------
qwerty 6 Typ=1 Len=6: 113,119,101,114,116,121



VARCHAR vs. VARCHAR2
---------------------
1. VARCHAR is going to be replaced by VARCHAR2 in next
version. So, Oracle suggests the use VARCHAR2 instead of
VARCHAR while declaring datatype.

2. VARCHAR can store up to 2000 bytes of characters while
VARCHAR2 can store up to 4000 bytes of characters.

3. If we declare datatype as VARCHAR then it will occupy
space for NULL values, In case of VARCHAR2 datatype it will
not occupy any space.


CHAR vs. VARCHAR
----------------

VARCHAR is used to store variable length character strings
up to 4000 characters. But, remember CHAR is faster than
VARCHAR - some times up to 50% faster.

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I install microsoft sql?

546


If the application is running very slow? At what points you need to go about the database in order to improve the performance?

578


what is difference between delete and truncate commands? : Sql dba

595


Which data dictionary views have the information on the triggers that are available in the database?

765


What is a data definition language?

570






Is pl sql and postgresql same?

593


How do you sort in sql?

622


What is pivot table in sql?

531


What is the use of procedures?

556


Differences between Oracle 9i and 10g (Probably in terms of SQL and PL/SQL)?

3124


What is record type in pl sql?

564


Which operator is used in query for pattern matching?

648


How insert into statements in sql?

601


How do I sort a table in sql?

612


How do you update a sql procedure?

537