Solved

datatype how many bytes does each char map to

Posted on 2004-08-06
2
3,054 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now