×
☰ See All Chapters

MySQL LENGTH Function

MySQL LENGTH function returns an integer value that represents the number of characters in the string.

MySQL LENGTH Function Syntax

LENGTH(arg)

arg is the argument for which you want get the length. This can be an expression or a direct value or a value from a column of any type.

MySQL LENGTH Function Example

Creating table for demonstrating LENGTH Function

CREATE TABLE NAME

(

  FNAME  VARCHAR(10 )    NOT NULL,

  LNAME  VARCHAR(10 )

);

Insert into NAME (FNAME, LNAME) Values ('ADI', 'TEMP');

Insert into NAME (FNAME, LNAME) Values ('NAVEEN', 'SHETTY');

Insert into NAME (FNAME, LNAME) Values ('ARJUN', 'SHETTY');

Insert into NAME (FNAME, LNAME) Values ('HARISH', 'GOWDA');

Insert into NAME (FNAME, LNAME) Values ('HARI', 'PRASAD');

Insert into NAME (FNAME, LNAME) Values ('ARJUN', 'SHETTY');

Insert into NAME (FNAME, LNAME) Values ('KIRAN', 'KUMAR');

COMMIT;

Example 1

SELECT LENGTH(FNAME), LENGTH(LNAME)

FROM NAME

mysql-length-function-0

Example 2

SELECT FNAME, LNAME, LENGTH(CONCAT(FNAME,LNAME)) AS NAME_LENGTH

FROM NAME

mysql-length-function-1


All Chapters
Author