简体   繁体   中英

MySQL store procedure syntax error

My mysql version is 5.5 and when run this mysql store procedure it's return this error.

Code:

CREATE DEFINER = CURRENT_USER PROCEDURE `getReceiptNumber`(IN bankcode 
varchar,IN receipttype varchar,OUT seq int)
BEGIN
    update receipt_number 
    set seq_number = (seq_number + 1) 
    where bank_code = bankcode and receipt_type = receipttype;
    select seq_number from receipt_number where bank_code = bankcode and 
receipt_type = receipttype into seq; 
END;

Table Structure:

CREATE TABLE `receipt_number` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `bank_code` varchar(255) DEFAULT NULL,
  `cur_date` varchar(255) DEFAULT NULL,
  `cur_year` int(11) DEFAULT NULL,
  `receipt_type` varchar(255) DEFAULT NULL,
  `seq_number` int(5) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

Error:

[Err] 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 'IN receipttype varchar,OUT seq int) BEGIN update receipt_number set seq_nu' at line 1

You have not mentioned the size for in parameter varchar,

Try below code.

DELIMITER $$
CREATE DEFINER = CURRENT_USER PROCEDURE getReceiptNumber(IN bankcode VARCHAR(10),IN receipttype VARCHAR(10),OUT seq INT)
BEGIN
    UPDATE receipt_number 
    SET seq_number = (seq_number + 1) 
    WHERE bank_code = bankcode AND receipt_type = receipttype;
    SELECT seq_number FROM receipt_number WHERE bank_code = bankcode AND 
receipt_type = receipttype INTO seq; 
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