Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use the LENGTH () function in MySQL

Shulou Source: shulou.com Published: 2022-05-31 10:53:41 10月03日 Update

This article mainly introduces how to use the LENGTH () function in MySQL. It is very detailed and has a certain reference value. Friends who are interested must finish it!

LENGTH ()

The LENGTH (str) and OCTET_LENGTH (str) functions return the byte length of a string, for example:

SELECT LENGTH ('MySQL string function') AS len1, OCTET_LENGTH ('MySQL string function') AS len2;len1 | len2 |-- +-+ 20 | 20 |

In utf8mb4 coding, a Chinese character occupies 3 bytes.

In addition, the CHAR_LENGTH (str) and CHARACTER_LENGTH (str) functions are used to return the character length of the string, that is, the number of characters. For example:

SELECT CHAR_LENGTH ('MySQL string function') AS len1, CHARACTER_LENGTH ('MySQL string function') AS len2;len1 | len2 |-- +-+ 10 | 10 |

The BIT_LENGTH (str) function returns the bit length (number of bits) of a string, for example:

SELECT BIT_LENGTH ('MySQL string function') AS len;len |-+ 160 |

A byte contains 8 bits.

These are all the contents of the article "how to use the LENGTH () function in MySQL". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Character function string byte length content article number that is value interest guy partner quantity more knowledge coding industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Linux Docker Xiaomi