MySQL 如何使用mysql函数返回表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13251672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:23:48 来源:igfitidea点击:
How to return the table using mysql Function
提问by Bharathi
I am using MySQL. I want to return the table using MySQL function. In SQL its working fine but not in MySQL. I attach my partial code
我正在使用 MySQL。我想使用 MySQL 函数返回表。在 SQL 中,它工作正常,但在 MySQL 中则不然。我附上我的部分代码
DELIMITER $$
CREATE FUNCTION myFunction() RETURNS @tmptable TABLE (item varchar(20))
BEGIN
insert into @tmptable(item) values('raja')
return
END; $$
回答by Rahul Tripathi
Using functions you can not return a table.
使用函数不能返回表。
However you can use stored procedure to return the table.
但是,您可以使用存储过程来返回表。
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `sp_Name`(OUT po_ErrMessage VARCHAR(200))
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SET po_ErrMessage = 'Error in procedure sp_Name';
END;
SELECT * FROM table_name;
END