MySQL Forums
Forum List  »  Stored Procedures

Re: Capitalize each word in a string ?
Posted by: Joe Zack
Date: November 11, 2008 07:11AM

I ended up writing one that's really similar to yours (Deepika), it's below in case anyone's interested:

(You can see a formatted/code-colored version here: http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/ )

CREATE FUNCTION CAP_FIRST (input VARCHAR(255))

RETURNS VARCHAR(255)

DETERMINISTIC

BEGIN
DECLARE len INT;
DECLARE i INT;

SET len = CHAR_LENGTH(input);
SET input = LOWER(input);
SET i = 0;

WHILE (i < len) DO
IF (MID(input,i,1) = ' ' OR i = 0) THEN
IF (i < len) THEN
SET input = CONCAT(
LEFT(input,i),
UPPER(MID(input,i + 1,1)),
RIGHT(input,len - i - 1)
);
END IF;
END IF;
SET i = i + 1;
END WHILE;

RETURN input;
END;

Options: ReplyQuote


Subject
Views
Written By
Posted
6127
August 24, 2008 07:50AM
5516
September 15, 2008 01:33PM
Re: Capitalize each word in a string ?
7088
November 11, 2008 07:11AM
4999
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.