2010-04-12 2 views
0

,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'; 
+0

이것은 쿼리가 아니므로 프로 시저 스크립트 – lexu

+0

@lexu 나중에 프로 시저를 만들지 만 왜 그 오류가 발생합니까? 완전성을 위해 – bala3569

+0

- MySQL에서 SP 내부에 세미콜론이 필요합니까? – Axarydax

답변

2

이것은이 문제를 조금만 최적화 할 수 있습니다. 하나의 쿼리가 수행 할 때 데이터 저장소를 두 번 누르는 이유는 무엇입니까? isDeleted 속성을 1로 설정하고 나중에 row_count 값을 확인하십시오.

BEGIN 
    UPDATE aboutus SET isDeleted = 1 WHERE aboutUsId = p_id AND isDeleted = 0; 
    IF (SELECT row_count()) <= 0 THEN 
    SELECT 'No record to delete'; 
    END IF; 
END 
0

'IF'의 'THEN'을 놓쳤습니다 ...

+0

@ 지앙 그것은 존재하는 진술 .. – bala3569

+0

@ ziang 그때 나던 일을 추가 ... – bala3569

+0

당신은 또한 끝이 필요해 if – zsong

0

세미콜론과 THEN과 함께 END IF가 누락되어 IF 문을 종료합니다.

관련 문제