Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when the size of a VARCHAR2 in Oracle is declared as 1 byte?

Tags:

I know that I can declare a varchar2 using the number of the characters that it should be able to contain.

However, in an Oracle database on which I am working, I found that a field (named PDF) is defined as follows:

VARCHAR2(1 BYTE) 

What does this mean? How many characters can it contain?

Another, related question: What is the difference between a VARCHAR and a VARCHAR2?

like image 527
AndreaNobili Avatar asked Jun 16 '15 10:06

AndreaNobili


People also ask

How many bytes is VARCHAR2 in Oracle?

Introduction to Oracle VARCHAR2 data type A VARCHAR2 column can store a value that ranges from 1 to 4000 bytes. It means that for a single-byte character set, you can store up to 4000 characters in a VARCHAR2 column. By default, Oracle uses BYTE if you don't explicitly specify BYTE or CHAR after the max_size .

What does VARCHAR2 20 byte mean?

VARCHAR2(20 BYTE) : Allows only the specified number of bytes to be stored in the column, regardless of how many characters this represents. VARCHAR2(20 CHAR) : Allows the specified number of characters to be stored in the column regardless of the number of bytes this equates to.

What is the default size of VARCHAR2?

Without specifying the maximum length for a VARCHAR2 parameter, the default is 4000 bytes.


1 Answers

You can declare columns/variables as varchar2(n CHAR) and varchar2(n byte).

n CHAR means the variable will hold n characters. In multi byte character sets you don't always know how many bytes you want to store, but you do want to garantee the storage of a certain amount of characters.

n bytes means simply the number of bytes you want to store.

varchar is deprecated. Do not use it. What is the difference between varchar and varchar2?

like image 162
Rene Avatar answered Oct 22 '22 16:10

Rene