create function getSerialNumber(in_type varchar(40)) returns int
BEGIN
	DECLARE sid INT;
	set sid=0;
-- SELECT order_number_ + 1 INTO sid from t_serial_number where type_='凭证号' AND year_=substr(date_format(sysdate(),'%Y%m%d'),1,4) ;
SELECT order_number_ + 1 INTO sid FROM t_serial_number WHERE type_=in_type AND year_='2018' ;
IF sid = 0 THEN 
set  sid = 1;
INSERT INTO t_serial_number (id, order_number_,type_,year_) VALUES (replace(uuid(),'-',''), sid,in_type,'2018');
ELSE UPDATE t_serial_number SET order_number_ = sid where type_=in_type AND year_='2018';
END IF;
RETURN sid;
END;

