MySQL Forums
Forum List  »  Stored Procedures

Re: Capitalize each word in a string ?
Posted by: Deepika Gupta
Date: August 20, 2008 01:32AM

I also had the same requirement some time back and this is the function I ended up with. Any comments.

create function uppercase(str varchar(255)) returns varchar(255)
return concat(upper(left(str,1)),lower(right(str,length(str)-1)))

create function initCaps(str varchar(255)) returns varchar(255)
begin
declare pos int;
set str = uppercase(str);
set pos = locate(' ',str);
if pos = 0 then
return str;
else
while pos != 0
do
set str = concat( substring(str,1,pos),upper(substring(str,pos+1,1)),substring(str,pos+2,length(str)) );
set pos = locate(' ',str,pos+1);
end while;
end if;
return str;
end;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Capitalize each word in a string ?
6000
August 20, 2008 01:32AM
5874
August 24, 2008 07:50AM
5222
September 15, 2008 01:33PM
6594
November 11, 2008 07:11AM
4757
August 24, 2008 07:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.