CREATE FUNCTION myFunction(id INT) RETURNS TABLE
BEGIN
RETURN SELECT * FROM board;
END
此查询提供以下错误:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE
答案 0 :(得分:14)
根据documentation on user defined functions in MySQL
您只能返回{STRING|INTEGER|REAL|DECIMAL}
CREATE [AGGREGATE] FUNCTION function_name RETURNS {STRING|INTEGER|REAL|DECIMAL}
SONAME shared_library_name
如果您想阅读select
结果集,则必须定义procedure
而不是function
。
DELIMITER //
DROP PROCEDURE IF EXISTS myProcedure //
CREATE PROCEDURE
myProcedure( id INT )
BEGIN
SELECT * FROM board
-- add where condition if required
WHERE Col_name = id
;
END
//
DELIMITER ;
你可以调用
这样的程序call myProcedure( 6 )
根据过程中使用的语句返回隐式对象。