Solved

datatype how many bytes does each char map to

Posted on 2004-08-06
2
3,100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

738 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