Sunday 13 January 2019

sql - How to lowercase the whole string keeping the first in uppercase in MYSQL




My Table column -



enter image description here




My expected Output to change in column -



Smith, Allen, Doyle, Dennis, Baker, Waker


This is what i tried, but not working :( -



UPDATE TABLE `employee`
SET last_name = UCASE(LEFT(lower(last_name), 1))


UPDATE TABLE `employee`
SET last_name = ucase(lower(last_name),1)


Followed this link too - Resource



ERROR --



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE `employee` SET last_name = UCASE(LEFT(lower(last_name), 1))' at line 1



Let me know what I am doing wrong and how to fix.


Answer



TABLE is a reserved keyword. It should be escaped with backtick.



I think TABLE should not be in your query, (i think it is a typo)



UPDATE employee
SET last_Name = CONCAT(UCASE(LEFT(last_Name, 1)), LCASE(SUBSTRING(last_Name, 2)))




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...