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 ?
6441
August 20, 2008 01:32AM
6310
August 24, 2008 07:50AM
5646
September 15, 2008 01:33PM
7311
November 11, 2008 07:11AM
5164
August 24, 2008 07:52AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

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.