Skip to content
Advertisement

How to make mysql function that return from the select result?

I want to create this function on mySql 8. It will create a sequence number like 00001,00002

i dunno whats wrong with this query but i always got this error.

I also tried with this query.

but still gave me with the same error. What could go wrong with my function query ?

Advertisement

Answer

Multiple datatype convertions are excess – MySQL will change the datatype implicitly according to the operation context.

All operations can be performed in single statement which makes both declared variable and BEGIN-END (and delimiter reassigning) unnecessary.

The code needs lastNumber to be convertable to numeric datatype. If not then both your and my code will fail in strict SQL mode. So I recommend to change the datatype of lastNumber CHAR(255) input parameter datatype to UNSIGNED / INT – this will allow to detect the value incorrectness on the function call stage, not in the function code.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement