MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old January 21st, 2013, 03:26 PM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ;

Reply With Quote
  #17  
Old January 21st, 2013, 04:03 PM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #18  
Old January 21st, 2013, 04:41 PM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #19  
Old January 21st, 2013, 04:46 PM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
What I need is the result of:
SELECT @@GLOBAL.sql_mode;

Reply With Quote
  #20  
Old January 21st, 2013, 04:50 PM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #21  
Old January 21st, 2013, 06:47 PM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #22  
Old January 22nd, 2013, 04:32 AM
Germaris Germaris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pierrefonds, QC Canada
Posts: 205 Germaris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #23  
Old January 22nd, 2013, 05:04 AM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #24  
Old January 22nd, 2013, 05:50 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 16 m 23 sec
Reputation Power: 1485
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

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesMySQL Help > Conversion in an INSERT query

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap