MySQL 存储过程语法错误
MySQL store procedure syntax error
我的 mysql 版本是 5.5,当 运行 这个 mysql 存储过程是 return 这个错误。
代码:
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结构:
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;
错误:
[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
您没有提到参数 varchar 的大小,
试试下面的代码。
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 ;
我的 mysql 版本是 5.5,当 运行 这个 mysql 存储过程是 return 这个错误。
代码:
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结构:
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;
错误:
[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
您没有提到参数 varchar 的大小,
试试下面的代码。
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 ;