mysql select调用存储过程,从select语句mysql调用用户定义的存储过程

本文介绍了如何在MySQL中从SELECT语句中正确调用用户定义的存储过程,对比了调用用户定义和系统存储过程的区别,并提供了正确的语法示例。当尝试直接在SELECT语句中使用CALL关键字调用用户存储过程时可能会遇到错误,但通过改变调用方式,如使用DELIMITER和CREATE PROCEDURE,可以成功执行。
摘要由CSDN通过智能技术生成

I am trying to call a user defined stored procedure from a select statement and its giving me an error. However when I call a system procedure it works just fine. Is there a way to call a user defined procedure from a select statement. This is for mysql

SELECT ID, email FROM user PROCEDURE simpleproc();

give me an error ERROR 1106 (42000): Unknown procedure 'simpleproc'

mysql> call simpleproc();

Query OK, 0 rows affected (0.21 sec)

where as

SELECT ID, email FROM user PROCEDURE ANALYSE();

works

解决方案

You can call stored procedure from select statement,To call a procedure you must use following syntax:

CALL stored_procedure_name (param1, param2, ....)

Such as, you can CALL following procedure:

DELIMITER //

CREATE PROCEDURE `procedure1`(IN var1 INT)

BEGIN

SELECT var1 + 2 AS result;

END//

as

CALL procedure1(10);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值