Oracle basic data type --- (string)

Source: Internet
Author: User

Oracle string format
 
First, we will introduce the char (N) and Varchar2 (N) formats.
Create table TEST_CHAR
(
CHAR_COL CHAR (10 ),
VARCHAR_COL VARCHAR2 (10 ),
);
SQL> insert into test_char (char_col, varchar_col) values ('20140901', '20160901 ');
SQL> commit;
SQL> select char_col, dump (char_col, 16) as d_char_col, varchar_col, dump (varchar_col, 16) as d_varchar_col from test_char;
 
CHAR_COL D_CHAR_COL VARCHAR_COL D_VARCHAR_COL
---------- Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
123 Typ = 96 Len = 10: 31,32, 33,20, 20,20, 20,20, 20,20 123 Typ = 1 Len = 3: 31,32, 33
 
As you can see, the char type is automatically followed by spaces if the length is not enough. For the varchar type, only '123' is stored '.
SQL> select to_number ('31', 'xx') from dual;
 
TO_NUMBER ('31', 'xx ')
--------------------
49
---- First, convert the hexadecimal data into a hexadecimal data.
SQL> select chr (49) from dual;
 
CHR (49)
-------
1
Get 49 characters.
Summary: oracle stores characters, which are converted to the corresponding ASCII code for storage.
 
SQL> insert into test_char (char_col, varchar_col) values ('Magic status', 'Magic status ');
SQL> commit;
 
Commit complete
 
SQL> select char_col, dump (char_col, 16) as d_char_col, varchar_col, dump (varchar_col, 16) as d_varchar_col from test_char;
 
CHAR_COL D_CHAR_COL VARCHAR_COL D_VARCHAR_COL
---------- Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
123 Typ = 96 Len = 10: 31,32, 33,20, 20,20, 20,20, 20,20 123 Typ = 1 Len = 3: 31,32, 33
Magic country Typ = 96 Len = 10: c9, f1, c6, e6, b5, c4, b9, fa, bc, d2 magic country Typ = 1 Len = 10: c9, f1, c6, e6, b5, c4, b9, fa, bc, d2
We can see that Chinese characters are stored in two bytes.
 
Next we will introduce NChar (N) and NVarchar2 (N ).
 
Create table TEST_NCHAR
(
CHAR_COL NCHAR (10 ),
VARCHAR_COL NVARCHAR2 (10)
);
 
 
SQL> insert into test_nchar (char_col, VARCHAR_COL) values ('20140901', '20160901 ');
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select char_col, dump (char_col, 16) as d_char_col, VARCHAR_COL, dump (VARCHAR_COL, 16) as d_VARCHAR_COL from test_nchar;
 
CHAR_COL D_CHAR_COL VARCHAR_COL D_VARCHAR_COL
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
123 Typ = 96 Len = 20: 123 31, 32, 33, 20, Typ = 1 Len = 6 :,
 
We can clearly see that the string '123456' is inserted at the same time, but the NChar is 0, 31, 123, that is to say: the high value is supplemented with 0 to supplement two bytes.
Summary: NChar and Nvarchar2 store all characters in two bytes.
The four types of characters and numbers are stored in ASCII codes.
You can view the character set of oracle:
SQL> select * from sys. props $ where name like '% CHARACTERSET % ';
 
Name value $ COMMENT $
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NLS_CHARACTERSET ZHS16GBK Character set
NLS_NCHAR_CHARACTERSET AL16UTF16 NCHAR Character set

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.