MySQL LENGTH() Function Examples
Let’s look at examples of the LENGTH function in MySQL.
Query:
SELECT LENGTH("w3wiki");
Output :
13
Now we will use the LENGTH() function and find the length of all the float values.
Query:
CREATE TABLE float061
(
user_id int NOT NULL AUTO_INCREMENT,
float_val float,
PRIMARY KEY(user_id)
);
INSERT float061(float_val)
VALUES (1.9);
INSERT float061(float_val)
VALUES (1.1);
INSERT float061(float_val)
VALUES (3.9);
INSERT float061(float_val)
VALUES (10.2);
INSERT float061(float_val)
VALUES (7.9);
SELECT LENGTH(float_val) FROM float061;
Output :
| LENGTH(float_val)|
-----------------------------
| 3 |
-----------------------------
| 3 |
-----------------------------
| 3 |
-----------------------------
| 4 |
-----------------------------
| 3 |
Using LENGTH() function and getting the length of the item given.
Query:
CREATE TABLE package099
(
user_id int NOT NULL AUTO_INCREMENT,
item VARCHAR(10),
mrp int,
PRIMARY KEY(user_id)
);
INSERT package099(item, mrp)
VALUES ('books', 350);
SELECT LENGTH(item) FROM package099;
Output :
5
MySQL LENGTH() Function
MySQL LENGTH() function returns the length of a string in bytes.
Contact Us