我想编写一个返回多行数据的 MySQL 存储函数。这可能吗?它似乎被锁定在 1 行——甚至无法返回 0 行。
例如
DELIMITER // create function go() RETURNS int deterministic NO SQL BEGIN return null ; -- this doesn't return 0 rows! it returns 1 row -- return 0 ; END // DELIMITER ;
虽然从 MySQL 存储过程返回 null
,但不会返回 0 行。它返回 1 行,其中包含值 null
。
我可以从 MySQL 函数返回 0 行或多于 1 行吗?
最佳答案
来自 MySQL 引用:
23.4.6: Can MySQL 5.0 stored routines return result sets?
Stored procedures can, but stored functions cannot. If you perform an ordinary SELECT inside a stored procedure, the result set is returned directly to the client. You need to use the MySQL 4.1 (or above) client-server protocol for this to work. This means that—for instance—in PHP, you need to use the mysqli extension rather than the old mysql extension.
关于MySQL 函数返回多于 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2891884/