-
Notifications
You must be signed in to change notification settings - Fork 0
/
capit.sql
28 lines (22 loc) · 875 Bytes
/
capit.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
DROP FUNCTION IF EXISTS cap1;
CREATE FUNCTION cap1(oldWord VARCHAR(255)) RETURNS VARCHAR(255)
RETURN CONCAT(UCASE(SUBSTRING(oldWord, 1, 1)),LCASE(SUBSTRING(oldWord, 2)));
DROP FUNCTION IF EXISTS cap2;
DELIMITER //
CREATE FUNCTION cap2(oldName VARCHAR(255), delim VARCHAR(1), trimSpaces BOOL) RETURNS VARCHAR(255)
BEGIN
SET @oldString := oldName;
SET @newString := "";
tokenLoop: LOOP
IF trimSpaces THEN SET @oldString := TRIM(BOTH " " FROM @oldString); END IF;
SET @splitPoint := LOCATE(delim, @oldString);
IF @splitPoint = 0 THEN
SET @newString := CONCAT(@newString, UC_FIRST(@oldString));
LEAVE tokenLoop;
END IF;
SET @newString := CONCAT(@newString, UC_FIRST(SUBSTRING(@oldString, 1, @splitPoint)));
SET @oldString := SUBSTRING(@oldString, @splitPoint+1);
END LOOP tokenLoop;
RETURN @newString;
END//
DELIMITER ;