如果您想获取结果集并在 FROM 子句中使用例程 - 否。 MySQL 中的存储例程(过程或函数)无法返回表作为结果值。
但您可以将函数用作简单值,例如 -
DELIMITER $
CREATE FUNCTION mul10(Param1 INT)
RETURNS INT(11)
BEGIN
RETURN Param1 * 10;
END
$
DELIMITER ;
CREATE OR REPLACE VIEW view1
AS
SELECT mul10(2) AS column1;
SELECT column1 FROM view1;
----------
20
If you want to get result-set and use routine in FROM clause - NO. Stored routines (procedures or functions) in MySQL cannot return tables as result value.
But you can use functions as simple values, for example -
DELIMITER $
CREATE FUNCTION mul10(Param1 INT)
RETURNS INT(11)
BEGIN
RETURN Param1 * 10;
END
$
DELIMITER ;
CREATE OR REPLACE VIEW view1
AS
SELECT mul10(2) AS column1;
SELECT column1 FROM view1;
----------
20
发布评论
评论(1)
如果您想获取结果集并在 FROM 子句中使用例程 - 否。 MySQL 中的存储例程(过程或函数)无法返回表作为结果值。
但您可以将函数用作简单值,例如 -
If you want to get result-set and use routine in FROM clause - NO. Stored routines (procedures or functions) in MySQL cannot return tables as result value.
But you can use functions as simple values, for example -