我写了这个函数:
delimiter //
CREATE FUNCTION randomDefVal(val varchar(30), tableName varchar(30))
returns varchar(30)
BEGIN
SET @query = concat('SELECT ',val,' FROM ',tableName,' ORDER BY rand() LIMIT 1;');
SET @result = NULL;
PREPARE stmt1 FROM @query;
return (EXECUTE stmt1);
END//
但我在最后一行有一个错误:
SQL Error (1336): Dynamic SQL is not allowed in stored function or trigger
这表明我不能写 'return (EXECUTE stmt1);' 如何返回值,这将是“执行”语句的结果?