如何调用存储过程并在MySQL上一次选择返回值

时间:2022-11-28 16:38:30

on MySQL, I know I can use stored procedure something like this

在MySQL上,我知道我可以使用像这样的存储过程

call someProcedure(@return);
select @return;

but is there some way you can do it with single query ? like this

但是有一些方法可以用单一查询来做到这一点吗?喜欢这个

select @return from (call someProcedure(@return) as sp 

thanks in advance :)

提前致谢 :)

1 个解决方案

#1


2  

Define Procedure

      mysql>    DELIMITER //

     mysql>  CREATE PROCEDURE simpleproc(OUT param1 INT)
         -> BEGIN
         ->      SELECT COUNT(*) INTO param1 FROM t;
         -> END //

call the procedure ->

调用程序 - >

     mysql>  CALL simpleproc(@a);

Show Output ->

显示输出 - >

  mysql> SELECT @a;

      +------+
      | @a   |
      +------+
      | 3    |
      +------+1 row in set (0.00 sec)

#1


2  

Define Procedure

      mysql>    DELIMITER //

     mysql>  CREATE PROCEDURE simpleproc(OUT param1 INT)
         -> BEGIN
         ->      SELECT COUNT(*) INTO param1 FROM t;
         -> END //

call the procedure ->

调用程序 - >

     mysql>  CALL simpleproc(@a);

Show Output ->

显示输出 - >

  mysql> SELECT @a;

      +------+
      | @a   |
      +------+
      | 3    |
      +------+1 row in set (0.00 sec)