The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
Page 2 -
Conversion in an INSERT query
Page 2 - Discuss Conversion in an INSERT query in the MySQL Help forum on Dev Shed. Conversion in an INSERT query MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 21st, 2013, 03:26 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by r937 oh, wait... could this be the problem?
try it like this --
Code:
DROP FUNCTION IF EXISTS uc_words;
DELIMITER ||
CREATE FUNCTION ...
|
Doesn't happen anything...
Not even an error message!
I used:
Code:
DROP FUNCTION IF EXISTS uc_words;
DELIMITER ||
CREATE FUNCTION uc_words(lastName TEXT)
RETURNS TEXT
NO SQL
DETERMINISTIC
COMMENT 'Title Case. Assumes that there arent numbers or weird chars'
BEGIN
-- loop counter
-- (change type if you expect input longer than 255 chars)
DECLARE i TINYINT UNSIGNED DEFAULT 1;
-- limit for i
DECLARE maxlen TINYINT UNSIGNED DEFAULT LENGTH(lastName) + 1;
-- current char
DECLARE ch CHAR(1) DEFAULT '';
-- output buffer
DECLARE str_out TEXT DEFAULT '';
-- a word is already started?
DECLARE in_word BOOL DEFAULT FALSE;
-- loop chars
WHILE i < maxlen DO
-- get current char
SET ch = SUBSTRING(str_in FROM i FOR 1);
IF ch REGEXP '[[:alpha:]]' THEN
-- letter
IF in_word IS TRUE THEN
-- word already started
SET str_out = CONCAT(str_out, LOWER(ch));
ELSE
-- word starts here
SET str_out = CONCAT(str_out, UPPER(ch));
SET in_word = TRUE;
END IF;
ELSE
-- no letter; add it and remember we're out of word
SET str_out = CONCAT(str_out, IF(ch, ch, ' '));
SET in_word = FALSE;
END IF;
SET i = i + 1;
END WHILE;
RETURN str_out;
END;
||
DELIMITER ;
|

January 21st, 2013, 04:03 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Location: Italy
Posts: 36
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
|
|
|
That's really strange... can you tell me the value of your SQL_MODE?
|

January 21st, 2013, 04:41 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by f_razzoli That's really strange... can you tell me the value of your SQL_MODE? |
@@GLOBAL.sql_mode (empty)
Last edited by Germaris : January 21st, 2013 at 04:44 PM.
|

January 21st, 2013, 04:46 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Location: Italy
Posts: 36
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
|
|
|
What I need is the result of:
SELECT @@GLOBAL.sql_mode;
|

January 21st, 2013, 04:50 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by f_razzoli What I need is the result of:
SELECT @@GLOBAL.sql_mode; |
This is what I get on one and only one row...
|

January 21st, 2013, 06:47 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Location: Italy
Posts: 36
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by Germaris 5.1.66
I replaced str_in by the name of the column on which the function applies.
Right? |
Sorry, I didn't read this before. I don't think you need to do this, because you will do something like:
INSERT INTO tab_name SET surname = uc_words('BROWN'), ...
Please try to insert the function exactly how I wrote it, before trying any changes.
|

January 22nd, 2013, 04:32 AM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205
Time spent in forums: 1 Day 22 h 19 m 6 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by f_razzoli Sorry, I didn't read this before. I don't think you need to do this, because you will do something like:
INSERT INTO tab_name SET surname = uc_words('BROWN'), ...
Please try to insert the function exactly how I wrote it, before trying any changes. |
Sorry for the trouble, it works nice.
It was my mistake...
Thank you very much!
PS: How could I mark your answer as THE solution?
|

January 22nd, 2013, 05:04 AM
|
|
Contributing User
|
|
Join Date: Jan 2013
Location: Italy
Posts: 36
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
|
|
I have no idea 
I'm new to this forum, you should ask some experienced user...
|

January 22nd, 2013, 05:50 AM
|
|
|
|
Try editing the first post in the thread and adding [Solved] to subject.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|