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

Answers were Sorted based on User's Feedback



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

Answer / pavan_1981

VARCHAR2(size):variable lenght character data maximum size
is 4000 and minimum is 1
char2(size):fixed lenght character data of lenght size bytes
minimum and default is 1 and maximum is 2000.

Is This Answer Correct ?    31 Yes 5 No

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

Answer / roopesh kumar

Varchar2: The max. allowed length is 4000 byte default 0
i.e. nothing. This is variable length datatype. it will
take only same space as value stored.

Char: Max. permitable length 2000 byte. Default length 0.
It will store value blank padded to right side till
full length as declared.

Ex. SQL> create table fg (d varchar2);
create table fg (d varchar2)
*
ERROR at line 1:
ORA-00906: missing left parenthesis


SQL> create table fg (d char);

Table created.

SQL> desc fg
Name Null? Type
------------------------------- -------- ----
D CHAR(1)
SQL> create table cher_chk (col1 char(12));

Table created.

SQL> insert into cher_chk values ('raj');

1 row created.
SQL> select length(col1) from cher_chk
2 /

LENGTH(COL1)
------------
12

Is This Answer Correct ?    17 Yes 5 No

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

Answer / sravanthi

Let us declare to variables as below:
v_empname CHAR2(10) := 'BILL';
v_depname VARCHAR2(10) := 'HRD';
the database allocates 10 bytes memory for v_empname and
just 3 bytes memory for v_deptname.
when a variable is declared varchar then the memory will be
allocated variably.
So,if one is not sure of the data that the variable is
going to hold then VARCHAR2 should be used instead of CHAR
during declaration.

Is This Answer Correct ?    3 Yes 1 No

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

Answer / 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

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

Answer / thilaga

char 2000 byres, varchar 4000 bytes

Is This Answer Correct ?    1 Yes 1 No

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

Answer / sushant

Both CHAR and VARCHAR2 types are used to store string values but both behave very differently.



CHAR should be used to store fix length strings. String values will be space/blank padded towards right before storing on disk. If this type is used to store varibale length strings, it will waste a lot of disk space. For example we can use it to store fields where we have one character only like IS_MINOR char (1). Here we will store only 'Y' or 'N' hence it becomes a prefect candidiate for char data type.


VARCHAR2 is used to store variable length character strings. The string value's length will be stored on disk with the value itself.


Explanation with an example could be found here :

http://www.oraclebin.com/2012/11/difference-between-char-and-varchar2.html

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

What are the advantages of sql? Explain

0 Answers  


Explain isolation levels. : Transact sql

0 Answers  


i have a column which may contain this kind of value: 123*67_80,12*8889_5,34*8_874 ,12*7_7 (can contain space before a comma, and this string length can be anything) now i want to split this value into two column like: column1: 123*67,12*8889,34*8,12*7 column2: 80,5,874,7 use function for this

0 Answers  


Where is sql database stored?

0 Answers  


How many unique keys can a table have?

0 Answers  






What is pl/sql table? Why is it used?

0 Answers  


Can we create clustered index without primary key?

0 Answers  


What is trigger with example?

0 Answers  


what is an extent ? : Sql dba

0 Answers  


how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(actual output) a b c d require output is a b c d

5 Answers   Honeywell, Interact,


What are the types of join and explain each?

0 Answers  


what are set operators in sql? : Sql dba

0 Answers  


Categories