MySQL – procedure ignoring the WHERE clause 프로시저에서 WHERE 절 무시할 때

By | 2023년 10월 12일
Table of Contents

MySQL – procedure ignoring the WHERE clause 프로시저에서 WHERE 절 무시할 때

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

원인

변수명과 컬럼명을 동일하게 설정했을 때 당연히 컬럼명을 찾아갈 것으로 생각하면 안된다.

declare isroomusing int default 1;

## ......

if (select exists(select 1 from tblroominfo WHERE isroomusing=1 AND roomseq=p_roomseq)) then
   set reterrmsg = CONCAT('이미 등록된 카드 일련번호 ',p_roomseq,': 중복 불가');
   set returnvalue = -1;
   leave proc_body;
end if;

해결

r.isroomusing 같이 이것이 컬럼명인 것을 명시해 주면 오류가 없다.
변수명 또한 컬럼명과 동일하게 만들지 말자.

declare in_isroomusing int default 1;

## ......

if (select exists(select 1 from tblroominfo r WHERE r.isroomusing=1 AND r.roomseq=p_roomseq)) then
   set reterrmsg = CONCAT('이미 등록된 카드 일련번호 ',p_roomseq,': 중복 불가');
   set returnvalue = -1;
   leave proc_body;
end if;

답글 남기기