Page 1 of 1

Create MySQL Functions...

Posted: Wed Aug 16, 2006 10:59 am
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?

Posted: Fri Aug 18, 2006 11:54 pm
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...

Posted: Fri Aug 18, 2006 11:59 pm
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

Posted: Sat Aug 19, 2006 3:30 am
by onion2k
CREATE FUNCTION can only return STRING, INTEGER, REAL, or DECIMAL.