Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many bytes does Oracle use when storing a single character?

I tried to look here:

http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i3253

And I understand that I have to provide string length for the column, I'm just not able to find out how many bytes oracle uses when storing a character. My limit is 500 characters, so if its 1 byte / character, I can create the column with 500, if its 2 byte / character then 1000, etc.

Anyone have a link to the documentation or know for certain?

In case it matters, the SQL is being called from PHP, so these are PHP strings I'm inserting into the database. Thanks.

like image 959
mr-sk Avatar asked May 17 '10 16:05

mr-sk


People also ask

How many bytes is a character in Oracle?

The datatype code of a column or object attribute is returned by the DUMP function. Variable-length character string having maximum length size bytes or characters. Maximum size is 4000 bytes or characters, and minimum is 1 byte or 1 character.

How many bytes is a character?

Eight bits are called a byte. One byte character sets can contain 256 characters. The current standard, though, is Unicode which uses two bytes to represent all characters in all writing systems in the world in a single set.

How many bytes is VARCHAR in Oracle?

The VarChar data type can store a character string of a maximum length of 4000 bytes.


2 Answers

the number of bytes needed to store a character will depend upon the character set. If you want to store 500 characters and don't know the character set of the target database you should create the column (or variable) as a VARCHAR2(500 CHAR) or CHAR(500 CHAR).

like image 53
Vincent Malgrat Avatar answered Oct 06 '22 06:10

Vincent Malgrat


A plain CHAR is not necessarily one byte, depending on the setting of NLS_LENGTH_SEMANTICS.

See Oracle's SQL Language Reference as a starting point. If you need to dig deeper, have a look at Oracle's Globalization Support Guide.

like image 30
Vadim K. Avatar answered Oct 06 '22 07:10

Vadim K.