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