MySQL 函数返回多于 1 行

标签 mysql function

我想编写一个返回多行数据的 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/

相关文章:

swift 类型类没有成员函数

ios - Swift:从实用程序类调用 UIAlertController

c++ - 动态数组和函数

c - 此示例导致c4028警告,为什么?

MySQL加载数据infile很慢

mysql - 无法找到的 MySQL 错误

php - Yii 关系错误尝试获取非对象的属性

jquery - 同时使用两个 jquery 函数

Mysql,新的基于区域磁盘的 HA 升级完成。我现在可以禁用 GTID 吗?

php - #1062 - 主键重复条目