Oracle data type char vs. varchar

Source: Internet
Author: User

Connect to a database using a Scott user

Create a new table

CREATE TABLE stu01 (name char (32));

Insert a piece of data

INSERT into stu01 values (' liuyueming ');

Inquire

SELECT * from Stu01;

PS: If you are using a client connection may not be able to see the data, you need to commit on the command line commit

Char (32) represents the longest 32 bits of the character type, if not enough 32 bits are filled with blanks

Use the dump (name) search to show that the characters are converted into character codes

Oracle's Common data types

1,char (size)

Holds a fixed-length string with a maximum of 2000 characters

PS: The length of a string is typically a multiple of 16

For example char (32), store 32 characters (beyond the limit, not enough 32 bits to use a space to complement)

An error message will appear if you exceed the insert

New table if more than 2000 will also error

2,VARCHAR2 (size)

Explanation: variable length, maximum can hold 4,000 characters

Create a new table

CREATE TABLE stu02 (name VARCHAR2 (16));

Inserting data and viewing it (which is longer and does not take a space)

  

The three characters of Leo are stored in the database, only 3 characters are used, and the remaining characters are recycled, improving utilization

Description

If our data is fixed-length, such as a mobile phone number (11-bit), such as a social security number, you should use an insert to store it, so

The advantage is that the query and retrieval speed is faster;

If the stored string length is not fixed, it is recommended to use VARCHAR2 (size)

Cause: When querying a field of type char, query as a whole, while VARCHAR2 is a comparison of data

Oracle data type char vs. varchar

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.