인지용

Mysql 프로시저 만들때 to your MySQL server version for the right syntax to use near 에러 본문

에러 해결

Mysql 프로시저 만들때 to your MySQL server version for the right syntax to use near 에러

인지용 2021. 11. 10. 21:06

대량의 데이터를 테이블에 저장하기 위해서

프로시저를 만드는데 

 

select * from board;

 

위 코드처럼 ;(세미콜론)이 들어가는 구문에서 

to your MySQL server version for the right syntax to use near 에러가 뜨길래 알아보니

구분 기호의 문제였다.

 

쿼리 끝낼 때 쓰는 세미콜론이 중간에 들어가서 그런 것이다.

 

 

 

해결방법

일단 구분 기호 ;(세미콜론)을 다른 기호로 바꿔주면 된다.

DELIMITER //

 

그 후 프로시저를 만들고 나선 다시 되돌려주면 된다.

DELIMITER ;

 

 

예시)

DELIMITER //
CREATE PROCEDURE select()
BEGIN
SELECT * FROM board;
END;
//
DELIMITER ;

 

 

프로시저 호출

CALL select();

 

 

프로시저 안에 select * from board; 말고

다른 쿼리를 넣어도 된다.

 

 

 

 

 

insert loop 프로시저 예시)

Drop procedure if exists test;

DELIMITER //
create procedure `test`()
BEGIN

DECLARE i INT DEFAULT 1;
WHILE ( i <= 500 ) DO
INSERT INTO member (username, password, createdDate)
values ('name', 'password', now());
SET i = i+1;
END WHILE;

END;
//
DELIMITER ;

 

 

 

 

 

출처

https://www.tutorialspoint.com/how-to-resolve-the-mysql-error-you-have-an-error-in-your-sql-syntax-check-the-manualthat-corresponds-to-your-mysql-server-version-for-the-right-syntax-to-use-near

 

How to resolve the MySQL error “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server v

How to resolve the MySQL error “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?” To avoid this type of error in MySQL stored procedure, you need to change the delimi

www.tutorialspoint.com