Oracle string type

Source: Internet
Author: User


Oracle string types: Oracle has four basic string types: CHAR, VARCHAR2, NCHAR, and NVARCHAR2. In Oracle, all strings are stored in the same format. The most comprehensive range of database blocks is 1 ~ The 3-byte length field is followed by the data. If the data is NULL, the length field indicates one, but the byte value is 0xFF. Www.2cto.com if a varchar2 (80) that contains "hello world" is in the block structure:

If the same information is stored in char (80), the block structure is as follows:

CHAR/NCHAR is actually disguised as VARCHAR2/NVARCHAR2. Based on this, I think we only need to consider these two types of strings: VARCHAR and NVARCHAR2. I have never seen which application is suitable for the CHAR type. Because the CHAR type always fills the string with spaces to reach a fixed width, we will soon find that, whether in the table segment or any index segment, CHAR occupies the largest storage space.

This is bad enough to avoid another important reason for using the CHAR/NCHAR type: the CHAR/NCHAR type will also cause confusion in applications that need to obtain this information. This is because when strings are compared, it may be affected if there are spaces. Use CHAR unless you are very certain about the length of the secondary field, varchar is used in other cases. Www.2cto.com if a column is not fixed-length data, the maximum length is 20. If we define this column as char type. In the future, when we use bind variables for query, for example, the parameter length of the passed column is 10. SQL is similar to this: select * from table_examp where column_exmp =? . Even if the database contains the corresponding data, it cannot be found because 10 spaces are added to the database, and no spaces are added to the passed parameters.

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.