代码:
DELIMITER $$
CREATE FUNCTION ecmsbackoffice.getSequence(delimeter VARCHAR(20)) RETURNS VARCHAR(20)
BEGIN
DECLARE result VARCHAR(20);
DECLARE buffer INT;
SET result = 0;
SET buffer = 0;
IF (delimeter='ORD')
THEN
IF (0=(SELECT COUNT(*) FROM id_generator WHERE seq_name=delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d')))
THEN INSERT INTO id_generator (seq_name,seq_date,seq_currval) VALUE ('ORD',DATE_FORMAT(NOW(),'%y%m%d'),0);
ELSEIF (delimeter='SLS')
THEN
IF (0=(SELECT COUNT(*) FROM id_generator WHERE seq_name=delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d')))
THEN INSERT INTO id_generator (seq_name,seq_date,seq_currval) VALUE ('SLS',DATE_FORMAT(NOW(),'%y%m%d'),0);
ELSEIF (delimeter='BAC')
THEN
IF (0=SELECT COUNT(*) FROM id_generator WHERE seq_name=delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d')))
THEN INSERT INTO id_generator (seq_name,seq_date,seq_currval) VALUE ('BAC',DATE_FORMAT(NOW(),'%y%m%d'),0);
END IF;
IF (delimeter='ORG') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='ORD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d');
ELSEIF (delimeter='SLS') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d');
ELSEIF (delimeter='CAT') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='PRD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='CPD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='BAC') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter AND seq_date=DATE_FORMAT(NOW(),'%y%m%d');
ELSEIF (delimeter='MEM') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='LDH') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='ODP') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='ODD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='SLD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='PLC') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
ELSEIF (delimeter='BAD') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name= delimeter;
END IF;
IF (delimeter='ORG') THEN SELECT CONCAT('ORG',LPAD(seq_currval,7,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='ORD') THEN SELECT CONCAT('ORD',DATE_FORMAT(NOW(),'%y%m%d'),LPAD(seq_currval,6,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='SLS') THEN SELECT CONCAT('SLS',DATE_FORMAT(NOW(),'%y%m%d'),LPAD(seq_currval,6,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='CAT') THEN SELECT CONCAT('CAT',LPAD(seq_currval,4,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='PRD') THEN SELECT CONCAT('PRD',LPAD(seq_currval,9,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='CPD') THEN SELECT CONCAT('CPD',LPAD(seq_currval,7,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='BAC') THEN SELECT CONCAT('BAC',DATE_FORMAT(NOW(),'%y%m%d'),LPAD(seq_currval,6,'0')) INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='MEM') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='LDH') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='ODP') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='ODD') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='SLD') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='PLC') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
ELSEIF (delimeter='BAD') THEN SELECT LPAD(seq_currval,9,'0') INTO result FROM id_generator WHERE seq_name = delimeter;
END IF;
RETURN result;
END $$
DELIMITER ;
错误: 错误代码:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 17 行的 'SELECT COUNT(*) FROM id_generator WHERE seq_name=delimeter AND seq_date=DATE_FOR' 附近使用正确的语法
我想做函数,但这个错误得到......请检查我不知道的代码..哪里错了..