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 ;