0% found this document useful (0 votes)
55 views3 pages

What Is Difference Between CHAR and Varchar2

CHAR should be used for storing fixed length character strings, as it will pad shorter strings with spaces to the defined length, while VARCHAR2 is for variable length strings and only stores the actual length of the string. Both types can store alphanumeric character strings, but CHAR wastes disk space if used to store variable length strings due to padding with spaces.

Uploaded by

Santhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

What Is Difference Between CHAR and Varchar2

CHAR should be used for storing fixed length character strings, as it will pad shorter strings with spaces to the defined length, while VARCHAR2 is for variable length strings and only stores the actual length of the string. Both types can store alphanumeric character strings, but CHAR wastes disk space if used to store variable length strings due to padding with spaces.

Uploaded by

Santhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

What is difference between CHAR and

VARCHAR2
Both CHAR and VARCHAR2 types are used to store character string values,
however, they behave very differently. The VARCHAR type should not be used:
CHAR
CHAR should be used for storing fixed length character strings. String values will be
space/blank padded before stored on disk. If this type is used to store variable length
strings, it will waste a lot of disk space.
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
Note: ASCII character 32 is a blank space.
VARCHAR
Currently VARCHAR behaves exactly the same as VARCHAR2. However, this type
should not be used as it is reserved for future usage.
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
VARCHAR2
VARCHAR2 is used to store variable length character strings. The string value's
length will be stored on disk with the value itself.
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

................................................................................................................................
..................................

What is Trunc function where we can use it.


What is Round function and Sign function.
What INSTRING AND SUB STRING.
Difference between Translate and Decode.
Difference between Delete and Truncate.
Which is faster Case or Decode.
What are pseudo columns in oracle
What is Implicit and Explicit cursor.
Difference between Primary key and Unique.
Difference between procedure and function.
Can we use Out parameter in Function.
Can we use return statement in procedure.
If we use out parameter in function and also use return statement , function return 2
values or one value.
What is advantages of Packages.

I have a package with 2 procedures and same name with different signature it is
possible.
How many types of trigger, instead of trigger.
What is mutating table, how to resolve the error.
What are pragma exception types.
Tell me how to delete duplicate rows on a table.
I have a table and create a row level trigger on a table, i deleted 10 records,how
many times records are deleted(raised another question now rows deleted what
happens)

You might also like