views:

412

answers:

3

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.

+1  A: 

A single CHAR will take 1 byte.

Try here:

http://ss64.com/ora/syntax-datatypes.html

Ardman
I did - I'm assuming the minimum being 1 is because that's the size of a single character. OK cool thanks.
Mr-sk
As pointed out in the other answers, a CHAR character may be multiple bytes.
Gary
+8  A: 

Hi Mr-sk,

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).

Vincent Malgrat
Ok - thanks, will research more to find what's appropriate.
Mr-sk
This is the answer that should be marked accepted. Additionally, if you want to see how many bytes it will take to store a particular string use the dump function.SELECT dump('my sort of long string') FROM DUAL;
Scott Bailey
@Scott: you can also use the `lengthb` function
Vincent Malgrat
+3  A: 

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.

Vadim K.
Ok will look here as well, thanks.
Mr-sk