Thursday, 27 June 2013

how many bytes take by varchar2 data type in oracle to store number or string values.

When we define varchar2 data type to particular column in table, same time we define its length or you can say its range but knowledge point is how many byte oracle server take? to store particular string or number values its depend upon the character set .So my this post explain to you  how many byte oracle server take to store values.

Explanation:-
                  
SQL> create table test(id varchar2(10);

     table created

SQL> insert into test values('abcdefghij');

    one row inserted

SQL>commit;

SQL> select length ('abcdefghij') from dual;   **/ length is 10 so no error  has been generated after execution of insert statement /*****

SQL> insert into test values('1234567891');
   
         one row inserted

SQL> commit;

SQL> select length('1234567891') from dual;      **/ length is 10 so no error  has been generated after execution of insert statement /*****

LENGTH('1234567891')
--------------------
                  10

SQL>insert into test values('12345678910');

ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."TEST"."ID" (actual: 11, maximum:
10)
             **/ After execution of statement oracle server gives error  because insert statement cross specified range /***

NOTE:- that's means oracle server allowed you to insert only number of numeric and string values as per you specified range of column while creation of table.


SQL>  create table test1 (id VARCHAR2(10 byte));

Table created.

note:- now oracle server take only10byte data that means insert only those numeric and string values which within 10 bytes.if numeric or string values cross 10 byte range then oracle server gives error.

No comments:

Post a Comment

work on autovacuum postgreSQL parameter

 In This blog, we are discussing the auto vacuum parameter on a small scale. we will understand the below parameters and will see how to mod...