- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement the opposite of INITCAP() functionality with MySQL?
The INITCAP() method display the first character in every word in uppercase and rest in lowercase.
To implement the opposite functionality, you need to create your own function in MySQL. Here’s the function −
mysql> delimiter // mysql> create function convertFirstLetterToLowerAndRemainingToCapital(value varchar(250)) returns varchar(250) deterministic begin declare valueLength int; declare l int; set valueLength = char_length(value); set value = upper(value); set l = 0; while (l < valueLength ) do if (mid(value,l ,1) = ' ' or l = 0) then if (l < valueLength ) then set value= concat( left(value,l), lower(mid(value,l+ 1,1)), right(value,valueLength - l - 1) ); end if; end if; set l = l + 1; end while; return value; end; // Query OK, 0 rows affected (0.17 sec) mysql> delimiter ;
Call the function with the help of select statement −
mysql> select convertFirstLetterToLowerAndRemainingToCapital('Introduction To MySQL');
This will produce the following output −
+-------------------------------------------------------------------------+ | convertFirstLetterToLowerAndRemainingToCapital('Introduction To MySQL') | +-------------------------------------------------------------------------+ | iNTRODUCTION tO mYSQL | +-------------------------------------------------------------------------+ 1 row in set, 2 warnings (0.04 sec)
Advertisements