Create a function in mysql to work with a sequence the code of the function is as follows:
FUNCTION 'fn_nextValue'(SEQNAME varchar(50)) RETURNS bigint(20)
BEGIN
DECLARE EXIST_SEQ INT;
DECLARE CUR_VALUE BIGINT(20);
SET EXIST_SEQ = (SELECT COUNT(1) FROM bd_triggers.secuencias WHERE nombreSecuencia = SEQNAME);
IF EXIST_SEQ > 0 THEN
UPDATE bd_triggers.secuencias
SET secuenciaValor = ((IFNULL(secuenciaValor,0) + secuenciaIncremento) < secuenciaMaximo,
IFNULL(secuenciaValor,0) + secuenciaIncremento,
secuenciaMaximo);
END IF;
SET CUR_VALUE = (SELECT secuenciaValor FROM bd_triggers.secuencias WHERE nombreSecuencia = SEQNAME);
RETURN CUR_VALUE;
END
For the sequence table which has the following structure:
A record already exists in my sequence table:
SEQ_ID |1 |1 |18446744073709551615 |NULL
But when trying to call the function:
SELECT bd_triggers.fn_nextValue ('SEQ_ID');
This error marks me:
Error Code 1241. Operand should contain 1 column(s)
If you could tell me where I made the mistake to correct it, they would help me a lot.