第二部分字符串函数
1. ASCII('str'): 返回字符串 str 中最左边字符的 ASCII 代码值。
2. BIN(N): 返回十进制数值 N 的二进制数值的字符串表现形式。
3. BIT_LENGTH(str): 返回字符串 str 所占的位长度。
4. CHAR(N,... [USING charset_name]): 会将每一个参数 N 都解释为整数,返回由这些整数在 ASCII 码中所对应字符所组成的字符串。
5. CHAR_LENGTH(str): 单纯返回 str 的字符串长度;
6. CONV(N,from_base,to_base): 将数值在不同进制间转换。
7. COMPRESS():压缩(不推荐使用 CHAR 或VARCHAR 来存储压缩字符串。最好使用一个 BLOB 列代替);
8. UNCOMOPRESS(): 解压内容
压缩实例:
MariaDB[study_db]> SELECT
-> LENGTH(REPEAT('a', 50)),
-> LENGTH(COMPRESS(REPEAT('a',50))),
-> COMPRESS(REPEAT('a',50)),
-> UNCOMPRESS(COMPRESS(REPEAT('a',50)));
+-------------------------+----------------------------------+--------------------------+----------------------------------------------------+
| LENGTH(REPEAT('a', 50)) | LENGTH(COMPRESS(REPEAT('a',50))) | COMPRESS(REPEAT('a',50)) | UNCOMPRESS(COMPRESS(REPEAT('a',50))) |
+-------------------------+----------------------------------+--------------------------+----------------------------------------------------+
| 50 | 16 | 2 x?KL$ ?\? | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+-------------------------+----------------------------------+--------------------------+----------------------------------------------------+
1 row in set (0.00 sec)
2.2大小写UPPER()与LOWER()
MariaDB[study_db]> select book_name, book_author_name FROM new_books;
+------------------+---------------------------+
|book_name|book_author_name|
+------------------+---------------------------+
|跟我学MariaDB|hhw|
|跟我学NodeJS|hhw|
|HTTP权威指南|O'Reilly|
|追风筝的人|Khaled Hosseini|
MariaDB [study_db]> select UPPER(book_name),LOWER( book_author_name) FROM new_books;
+------------------+---------------------------+
|UPPER(book_name)|LOWER( book_author_name)|
+------------------+---------------------------+
|跟我学MARIADB|hhw|
|跟我学NODEJS|hhw|
|HTTP权威指南|o'reilly|
|追风筝的人|khaled hosseini|
|小王子|antoine marie jean-b|