Create MySQL Functions...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Create MySQL Functions...

Post by Todd_Z »

Code: Select all

CREATE FUNCTION get_client_md5 ( cid int(10) unsigned )
  RETURNS VARCHAR(32)
  SELECT MD5(CONCAT_WS('|',name,number)) FROM client WHERE id = cid
;
ERROR 1415 (0A000): Not allowed to return a result set from a function

The query should return a varchar(32), not a set... what am i missing?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you alias the return?

Code: Select all

CREATE FUNCTION get_client_md5 ( cid int(10) unsigned )
  RETURNS VARCHAR(32)
  SELECT MD5(CONCAT_WS('|',name,number)) AS return FROM client WHERE id = cid
;
I am just throwing something out there. I am not sure if this will work...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe a cast?

it should return a CHAR(32). MD5() always returns 32 characters when output in hex.

http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

CREATE FUNCTION can only return STRING, INTEGER, REAL, or DECIMAL.
Post Reply