Easy way to update certain field in database that is upper case?
I am looking to update the field 'prefix' in my course table to just have the FIRST letter capitalized and not the whole prefix.
Is there any easy way to do this is SQL?? Sample Output could look like 'Aadm' in the database for 'prefix'.
My table looks like:
Sample rows look like:
开发者_StackOverflow中文版I have SQL that looks like:
WHERE CONCAT(prefix,code) LIKE '%". $keywords . "%'");
Is it possible to user LOWER on prefix here?
select prefix,
concat(upper(substring(prefix,1,1)),substring(lower(prefix) from 2)) as initcap
from course
try it in select form before update your field
if you're looking for prefixes where all chars are upper case use a regexp
where binary(prefix) regexp '^[A-Z]+$'
EDIT. Update query
update course
set prefix =
concat(upper(substring(prefix,1,1)),substring(lower(prefix) from 2))
精彩评论