[英]EXISTS and output parameter in stored procedure in mysql
Here is my stored procedure for returning true if any data is found in document details but it generates an error 这是我的存储过程,如果在文档详细信息中找到任何数据,则返回true,但会产生错误
" #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 '@result = true end if end' at line 5" “#1064-您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以在第5行的'@result = true end if end'附近使用正确的语法”
create procedure abcde(out result boolean)
begin
if exists(select * from document_details)
then @result = true;
end if
end
Kindly,provide me a solution asap 请尽快为我提供解决方案
Besides the fact that you need to use SET
to assign a value to a local variable or a parameter, there are other things worth mentioning 除了需要使用
SET
将值分配给局部变量或参数这一事实外,还有其他事情值得一提
END IF
END IF
之后必须用分号 EXSITS()
returns BOOLEAN
you can just directly assign it to your OUT
parameter EXSITS()
返回BOOLEAN
您可以直接将其分配给OUT
参数 That being said your stored procedure might look like 话虽这么说,您的存储过程可能看起来像
CREATE PROCEDURE abcde(OUT result BOOLEAN)
SET result =
(
EXISTS(SELECT *
FROM document_details)
);
Note: now it's just one statement. 注意:现在这只是一个陈述。 Therefore you don't even need to change
DELIMITER
and use BEGIN ... END
block. 因此,您甚至不需要更改
DELIMITER
并使用BEGIN ... END
块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.