Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3138
  • Last Modified:

datatype how many bytes does each char map to

datatype how many bytes does each char map to
VARCHAR2
NVARCHAR2
CHAR
NCHAR
NUMBER
PLS_INTEGER
RAW
0
bolicat
Asked:
bolicat
1 Solution
 
jasonwisdomCommented:
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
 
LowfatspreadCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now