Length Function - How to get Data of String in Bytes in MySQL
Length function is used to return the size of string in Bytes in MySQL. It is equivalent to DataLength( ) Function in SQL Server.
Syntax:
Select Length('StringValue');
Let's say we have customer table with some records and we would like to get the data length for firstname and lastname values.
CREATE TABLE `customer` (
`idcustomer` int,
`firstname` varchar(50) NULL,
`lastname` varchar(30) NULL,
`age` int(11) DEFAULT NULL,
`phonenumber` char(11) DEFAULT NULL,
`dob` date DEFAULT NULL,
`gender` char(1) NOT NULL
) ;
-- Insert sample records
insert into customer(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Raza',null,39,'505-4141969','1980-01-01','M'),
(2,'Aamir','Naz',39,'505-4141969','1980-01-01','M'),
(3,'Aamir','Shahzad',39,'505-4141900','1980-01-01','M'),
(4,'Aamir1','Shahzad',39,'505-4141900','1980-01-01','M'),
(5,'Robert','Ladson',69,'505-345900','1960-01-01','M');
use Length( ) function to get the size of column values in Bytes.
Select firstname,length(firstname), lastname,length(lastname),phonenumber,length(phonenumber) from customer;
CREATE TABLE `customer` (
`idcustomer` int,
`firstname` varchar(50) NULL,
`lastname` varchar(30) NULL,
`age` int(11) DEFAULT NULL,
`phonenumber` char(11) DEFAULT NULL,
`dob` date DEFAULT NULL,
`gender` char(1) NOT NULL
) ;
-- Insert sample records
insert into customer(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Raza',null,39,'505-4141969','1980-01-01','M'),
(2,'Aamir','Naz',39,'505-4141969','1980-01-01','M'),
(3,'Aamir','Shahzad',39,'505-4141900','1980-01-01','M'),
(4,'Aamir1','Shahzad',39,'505-4141900','1980-01-01','M'),
(5,'Robert','Ladson',69,'505-345900','1960-01-01','M');
use Length( ) function to get the size of column values in Bytes.
Select firstname,length(firstname), lastname,length(lastname),phonenumber,length(phonenumber) from customer;
How to get size of Column in MySQL by using Length ( ) Function - MyQL Tutorial
Good blog, its really very informative, do more blog under good concepts.
ReplyDeleteDOT NET Training in Bangalore
DOT NET Training in Chennai
DOT NET Training Institutes in Bangalore
DOT NET Course in Bangalore
Best DOT NET Training Institutes in Bangalore
DOT NET Institute in Bangalore
AWS Training in Bangalore
Data Science Courses in Bangalore
DevOps Training in Bangalore
PHP Training in Bangalore
Great information. The above content is very interesting to read. This will be loved by all age groups.
ReplyDeletewhich cloud computing certification is best
robotic process automation scope
best digital marketing certification
hadoop interview questions and answers for experienced
Awesome article!!! Eagerly waiting for your new article... thanks for sharing with us.
ReplyDeleteadvantages of seo
how to improve english pronunciation
web design using html
automation testing tools
salesforce interview questions for freshers
salesforce developer interview questions and answers
Fabulous post... Keep sharing
ReplyDeleteBest English Coaching Courses in Chennai
Spoken English Courses in Chennai
Amazing blog...keep sharing
ReplyDeleteIELTS Training in Chennai
IELTS Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching centre in Chennai
Wonderful Blog.. keep updating
ReplyDeleteAWS Training in Chennai
Amazon web services Training in Chennai
AWS Training Institutes in Bangalore
AWS Certification Training in Bangalore
nice article. thanks for sharing.
ReplyDeleteSQL Classes in Pune