Solved

datatype how many bytes does each char map to

Posted on 2004-08-06
2
3,064 Views
Last Modified: 2008-01-09
datatype how many bytes does each char map to
VARCHAR2
NVARCHAR2
CHAR
NCHAR
NUMBER
PLS_INTEGER
RAW
0
Comment
Question by:bolicat
2 Comments
 
LVL 1

Accepted Solution

by:
jasonwisdom earned 125 total points
ID: 11736587
It takes as many bytes to store one of these fields as there are characters in that field.

VARCHARs and CHARs work a bit differently.
If you have a VARCHAR2 with size 100 and your entry takes 12 characters, it will store 12 bytes.

CHAR is a fixed field size, so if you have an 8-dimensioned CHAR field, it will take 8 bytes, no matter whether you have 8 characters or 2 characters stored in it.

CHAR=NCHAR, VARCHAR2=NVARCHAR2.  

A RAW is a variable-length datatype, up to 2000 characters/bytes.  A LONG RAW allows much longer record storage.

As for calculating the # of bytes for a NUMBER field, this can get tricky.  Check out this article:
http://oracle.ittoolbox.com/documents/document.asp?i=1170

PLS_INTEGER is not an Oracle datatype, it is only valid with PL/SQL.

0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 11737783
The answer depend on the DBMS you are working with...

in general

char's use 1 byte per defined length
nchar's use 2 bytes per defined length character
both the above are "Fixed" length

Varchar/NVarchar  have a maximum length defined (and use either 1 or 2 bytes per character)
    there is also a length overhead for variable length columns which is normally 2 bytes for lengths under 4096
    and then will be 4 bytes above...
     (Only the actual used length of the column will be stored)

another modification / factor is whether the column is nullable or not
if null then typically a bit flag in the row will be used to indicate wether the column is null or not (so 1 byte per 8 nullable columns)... I think some DBMS use a similar idea for columns with default values...

so it really does depend on the DBMS (& OS and Version ) your using...
 
 
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now