コード:
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 構文にエラーがあります。17 行目の 'SELECT COUNT(*) FROM id_generator WHERE seq_name=delimeter AND seq_date=DATE_FOR' 付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。
関数を作成したいのですが、このエラーが発生します...わからないコードを確認してください..どこが間違っているのですか..