我用下面的MySQL查詢,mysql查詢有什麼問題?
DELIMITER $$
DROP PROCEDURE IF EXISTS `allied`.`aboutus_delete`$$
CREATE DEFINER=`allied`@`%` PROCEDURE `aboutus_delete`(
IN p_Id int(11)
)
BEGIN
if exists( select aboutUsId
from aboutus
where aboutUsId=p_id
and isDeleted=0
)
update aboutus set isDeleted=1 where aboutUsId=p_id
else
select 'No record to delete'
END$$
DELIMITER ;
但是,當我執行它,我得到這個錯誤...
Error Code : 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
'update aboutus set isDeleted=1 where aboutUsId=p_id
else
select 'No record to' at line 6
編輯:
使用分號似乎不工作,
if exists(select aboutUsId from aboutus where aboutUsId=p_id and
isDeleted=0) then
update aboutus set isDeleted=1 where aboutUsId=p_id;
else
select 'No record to delete';
這不是一個查詢,它是一個程序創建腳本 – lexu 2010-04-12 06:40:04
@lexu亞其程序,但爲什麼我得到那個錯誤? – bala3569 2010-04-12 06:45:50
只是爲了完整性 - 是MySQL內部SP所需的分號嗎? – Axarydax 2010-04-12 06:49:46