Wednesday , 3 September 2014
Home » MYSQL » UCFIRST-Make first character Capital using MYSQL
UCFIRST-Make first character Capital using MYSQL

UCFIRST-Make first character Capital using MYSQL

Hello Friends,

MySQL database is the world's most popular open source database because of its fast performance, high reliability, ease of use, and dramatic cost savings. As i am using MYSQL with developing my PHP web application, i need to make a simple String operation in MYSQL and i would like to share it with you guys. I need to make a table field values to uppercase first character and than lowercase all other characters. There are UPPER and LOWER inbuilt functions available in MYSQL but it will make values to either uppercase or lowercase. If you need to make database field value to UCFIRST (Capitalize the first letter of each word using MYSQL) than below is the query. You can run it in mysql query command. This behave same as ucfirst function of PHP.

UPDATE countries SET `v_name` = CONCAT(UCASE(SUBSTRING(`v_name`, 1, 1)),LOWER(SUBSTRING(`v_name`, 2)));

If you find any problem in this than let me know by comment.

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel AKA WordPress Freelancer working as PHP Programmer India. I am here to share all my developing knowledge, quick coding techniques, quick solutions to save your time and help you guys for any issue or bug fixing. If you have any PHP, WordPress, Magento related work, please contact me. I am interested for the work.

2 comments

  1. This only does the first word not each word like the PHP function.

  2. This is exactly what I was looking for! Thanks a bunch. It’s now part of my SQL txt cheat sheet. :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>