Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
PLSQL | LENGTH4 Function
Next article icon

MySQL LENGTH() Function

Last Updated : 10 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

MySQL LENGTH() function returns the length of a string in bytes.

Syntax

The MySQL LENGTH function syntax is:

LENGTH(string)

Parameters

The LENGTH function accepts only one parameter.

  • string: A specified string whose length is to be counted.

MySQL LENGTH() Function Examples

Let’s look at examples of the LENGTH function in MySQL.

Query:

SELECT LENGTH("GEEKSFORGEEKS");

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


Next Article
PLSQL | LENGTH4 Function
author
nidhi1352singh
Improve
Article Tags :
  • Databases
  • SQL
  • DBMS-SQL
  • mysql

Similar Reads

  • PLSQL | LENGTH Function
    The PLSQL LENGTH function is used for returning the length of the specified string, in other words, it returns the length of char. The char accepted by the LENGTH function in PLSQL can be of any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The value returned by the LENG
    1 min read
  • PLSQL | LENGTHC Function
    The PLSQL LENGTHC function is used for returning the length of the specified string using UNICODE complete characters. The char accepted by the LENGTHC function in PLSQL can be of any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The value returned by the LENGTHC functio
    1 min read
  • PLSQL | LENGTHB Function
    The PLSQL LENGTHB function is used for returning the length of the specified string using bytes instead of characters. The char accepted by the LENGTHB function in PLSQL can be of any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The value returned by the LENGTHB functio
    1 min read
  • PLSQL | LENGTH2 Function
    The PLSQL LENGTH2 function is used for returning the length of the specified string, in other words, it returns the length of char. UCS-2 codepoints is a character encoding standard in which characters are represented by a fixed-length 16 bits (2 bytes). UCS-2 represents a possible maximum of 65, 53
    2 min read
  • PLSQL | LENGTH4 Function
    The PLSQL LENGTH4 function is used for returning the length of the specified string, using UCS4 code points. UCS-4 codepoints is a character encoding which allows the representation of each value as exactly four bytes (one 32-bit word). UCS-4 represents a possible value between 0 and hexadecimal 7FF
    2 min read
  • BIT_LENGTH() Function in MySQL
    BIT_LENGTH() function in MySQL is used to find the length of a given string in bits. The input string can be a character string or number string. Syntax : BIT_LENGTH(str) Parameter : Required. str : A string whose bits length to be calculated. Returns : It returns the length of a given string in bit
    1 min read
  • CHAR_LENGTH() Function in MySQL
    CHAR_LENGTH() function in MySQL is used to find the length of a given string (in characters). It counts the number of characters and ignore whether the character(s) are single-byte or multi-byte. Syntax : CHAR_LENGTH(str) Parameter : This method accepts one parameter as mentioned above and described
    1 min read
  • LEFT() Function in MySQL
    The LEFT() function in MySQL is used to extract a specified number of characters from the left side of a given string. It uses its second argument to decide, how many characters it should return. Syntax: LEFT (str, len)Parameter: This function accepts two parameters as mentioned above and described
    1 min read
  • LN() Function in MySQL
    LN() function : It is the function in MySQL is used to calculate the natural logarithm of a specific number with base e . The number must be greater than 0, otherwise it will return NULL. Syntax : LN(X) Parameter : LN() function accepts one parameter as mentioned above in the syntax and described be
    2 min read
  • OCTET_LENGTH() Function in MySQL
    In this article, we are going to cover the OCTET_LENGTH function. And will see syntax and example of OCTET_LENGTH function. Let's discuss one by one. OCTET_LENGTH function in MySQL is used to returns the number of characters in a given string. Syntax : OCTET_LENGTH( str ) Parameter : This function a
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences