Php 在mysql中创建存储过程时显示语法错误 错误1064(42000):您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用“from”附近的正确语法 tbl_PurchaseReturn详细信息 其中(purchaseDetailsId=p_purchaseDetailsId)’位于第5行
试试这个: ERROR 1064 (42000): 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 'from tbl_PurchaseReturnDetails where (purchaseDetailsId = p_purchaseDetailsId)' at line 5Php 在mysql中创建存储过程时显示语法错误 错误1064(42000):您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用“from”附近的正确语法 tbl_PurchaseReturn详细信息 其中(purchaseDetailsId=p_purchaseDetailsId)’位于第5行,php,mysql,sql,Php,Mysql,Sql,试试这个: ERROR 1064 (42000): 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 'from tbl_PurchaseReturnDetails where (purchaseDetailsId = p_purchaseDetai
每个错误消息都显示可能的错误所在。
在你的例子中,它说,
。。。对于要使用near'from的正确语法
tbl_PurchaseReturnDetails…
当它在附近显示时,表示错误在该特定语句之前。
因此,来自
的前面的语句是错误的。你把右括号放错地方了
更改语句:
create procedure purchaseDetailsCheckOnDelete(p_purchaseDetailsId varchar(50))
begin
declare p_Exist tinyint(1);
set p_Exist = False ;
select p_Exist = case count(purchaseDetailsId) when '0' then False else True end from tbl_PurchaseReturnDetails
where purchaseDetailsId = p_purchaseDetailsId;
select p_Exist ;
end
至:
select p_Exist =
( case count(purchaseDetailsId) when '0' then False else True end
from tbl_PurchaseReturnDetails
where (purchaseDetailsId = p_purchaseDetailsId) );
如果决定使用括号,则缺少一个select
,即
select p_Exist =
( case count(purchaseDetailsId) when '0' then False else True end )
from tbl_PurchaseReturnDetails
where (purchaseDetailsId = p_purchaseDetailsId);
或者,放下支架
select p_Exist =
(select case count(purchaseDetailsId)
编辑
更简短的是:
select p_Exist = case count(purchaseDetailsId)
when '0' then False else True end
from tbl_PurchaseReturnDetails
where purchaseDetailsId = p_purchaseDetailsId;
使用此代码段
SELECT IFNULL((select 1 from tbl_PurchaseReturnDetails
WHERE purchaseDetailsId = p_purchaseDetailsId), 0) AS p_Exist;
不可能。。(没有错误)
SELECT IFNULL((select 1 from tbl_PurchaseReturnDetails
WHERE purchaseDetailsId = p_purchaseDetailsId), 0) AS p_Exist;
delimiter //
drop procedure if exists purchaseDetailsCheckOnDelete;
create procedure purchaseDetailsCheckOnDelete(p_purchaseDetailsId varchar(50))
begin
declare p_Exist tinyint(1);
set p_Exist = False ;
select p_Exist = (case count(purchaseDetailsId) when '0' then False else True end) as 'P_EXIST'
from tbl_PurchaseReturnDetails
where (purchaseDetailsId = p_purchaseDetailsId);
select p_Exist ;
end//