Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday, 21 February 2024

length Function in MYSQL

In MySQL, the LENGTH function is used to return the length of a string in bytes. Here's how you can use the LENGTH function with an example:


SELECT LENGTH('Hello World') AS string_length;


In this example, 'Hello World' is a string literal. The LENGTH function is applied to this string, and it returns the length of the string, which is 11 bytes.


The output of this query would be:


string_length

-------------

11

This demonstrates how to use the LENGTH function in MySQL to find the length of a string in bytes. If you want to count the number of characters instead of bytes in MySQL, you should use the CHAR_LENGTH function instead of LENGTH.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.