简体   繁体   中英

Mysql procedure giving error

CREATE PROCEDURE 
  myProcedure( id INT )
BEGIN  
SELECT * FROM `board`;
END 

//check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

Check if this solves the error

Delimiter //

CREATE PROCEDURE 
    myProcedure( id INT )
BEGIN  
SELECT * FROM board;
END 
//

use delimeter

delimiter //
CREATE PROCEDURE 
  myProcedure( id INT )
BEGIN  
SELECT * FROM `board`;
END //

There are two ways:

Way 1 :

When there is only one executable statement in the procedure body, using BEGIN - END is optional. And when used, you have to use custom DELIMITER .

CREATE PROCEDURE myProcedure( id INT )
  SELECT * FROM `board`;

Way 2 :

Define custom DELIMITER , define procedure, and then reset the delimiter.

DELIMITER //

DROP PROCEDURE IF EXISTS myProcedure //

CREATE PROCEDURE myProcedure( id INT )
BEGIN
  SELECT * FROM `board`;
END;
//

DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM