test

1.    It is used to store fixed length values.

2.    By default, the size is 1 character, and max size is 2000 chars or bytes.

3.     If the data is less than the original specified size, blank pads are applied.

4.     If you try to insert a value that is too long for the column, then Oracle returns an error.

5.     A 1-byte string can be inserted into a CHAR (10) column, but the string is blank-padded to 10 bytes before it is stored.

6.     If you don’t explicitly specify BYTE or CHAR followed the length, Oracle uses the BYTE by default

7.     The Size of a Character Can Range From 1 Byte to 4 Bytes Depending on The Database Character Set.

           CHAR(length CHAR)

CHAR(length BYTE)

Example Blank Space usage:

 

 

create table test_Spaces(

    name char(20),

    ename varchar2(20)

);

 

insert into test values('welcome', 'welcome1');

 

       select * from test;

Output:

                  

NAME

ENAME

Welcome            

Welcome1

 

CREATE TABLE test_dump (

    col1 NUMBER5, 2),

    col2 FLOAT(5)

);

INSERT INTO test VALUES (1.23, 1.23);

INSERT INTO test VALUES (7.89, 7.89);

INSERT INTO test VALUES (12.79, 12.79);

INSERT INTO test VALUES (123.45, 123.45);

 


 

select name,dump(name),ename,dump(ename) from test;

 


Output:

 

NAME

DUMP(NAME)

welcome            

Typ=96 Len=20: 119,101,108,99,111,109,101,32,32,32,32,32,32,32,32,32,32,32,32,32

 

ENAME

DUMP(ENAME)

welcome1

Typ=1 Len=8: 119,101,108,99,111,109,101,49

 

Dump function to return the detailed information of columns:

The string Oracle takes 7 bytes but padded 13 more spaces on the right of the string to make its length 20 bytes for the name column. It is not the case for the ename column because the data type of ename column is a variable-length character string (VARCHAR2).

 

select name,length(name),ename,length(ename)from test;

 

Output:

 

NAME

LENGTH(NAME)

ENAME

LENGTH(ENAME)

welcome            

20

welcome1

8

No comments:

Post a Comment