The difference between char types in MySQL (5.0) and Oracle (11g) (stepped on the pit)

1: char in mysql

CHARThe data type is a fixed-length character type in MySQL. We often declare CHARtypes whose length specifies the maximum number of characters to store. For example, CHAR(20)it can hold up 20to characters.

If the data to be stored is of fixed size, you should use a CHARdata type. In this case you will get better performance compared to VARCHAR.

CHARThe length of the data type can be any value from 0to . 255When storing a CHARvalue, MySQL pads its value with spaces to the declared length.

When querying for CHARvalues, MySQL removes trailing spaces .


Note: 1. The number of characters stored is 20, please pay attention to the number of bytes;

           2. Store up to 20, or you can store 10, 11, etc.

2 : oarcle 中 char

char(20) ----> means: 20 bytes stored in oralce, when the number of digits is not enough, it will be supplemented with spaces. Whitespace is also not stripped when querying. Field values ​​are formed together with spaces.


Special attention is required in designing the database. I used oracle a lot before, and now I use mysql. I have a deep understanding of the difference and the real usage of the two.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326825807&siteId=291194637