I’m trying to develope a function and I get a mistake, please where is this mistake? Thanks. This is the code:
mysql> DELIMITER //
mysql> CREATE FUNCTION anumero (cadena varchar(20)) returns INT
-> DETERMINISTIC
-> BEGIN
-> DECLARE LARGO,I int DEFAULT 0;
-> DECLARE N VARCHAR(20) DEFAULT "";
-> SET I =1;
-> SET LARGO = LENGTH(CADENA);
-> REPEAT
-> IF INSTR('0123456789',SUBSTRING(CADENA,I,1))>0 THEN
-> SET N= CONCAT(N,SUBSTRING(CADENA,I,1));
-> END IF;
-> SET I = I+1;
-> UNTIL I > LARGO
-> END REPEAT;
-> return CAST (N as binary);
-> END //
ERROR 1064 (42000): 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 ‘binary);
END’ at line 15
In MySQL you must not write any character between a function name and it’s arguments.
So, your
returnstatement should be:return CAST(N as binary);