previously used SQL SERVER is often used when function , the processing of some data is more convenient, now the database is transferred to MySQL after that, I also want to keep the same function, fortunately MySQL also supports function , now to share under the MySQL in how to create function
Tools / Raw Materials
MySQL
MySQL Workbench
Method / Steps
1in theMySQLcreated infunctionthe wording andSQL SERVERThere is a difference, first look at theMySQLWhat is the correct wording in thisfunctionThe goal is to return the number of peers based on the age parameter passed and return the results
call our newly created function , we can see from the results that our custom function properly executed, and the following is speaking MySQL Create function things to be aware of when
DELIMITER usage is no longer described, as in stored procedures, I share how to create stored procedures have been described??
It is important to note here that the parameters passed in cannot be the same as the database fields, which I was not aware of before . function It 's never been executed in the ideal state.
in this step we will define the parameters as well as the database fields to see how the function what kind of value will be returned
Although function can also be created successfully, but the return value is not the value we want when we call it. function does not work as we wish, so it is a special reminder that the arguments passed in cannot be the same as the database fields
MySQL the variables defined in the SQL Server It's a lot easier to use without declaring it directly.
< Span style= "COLOR: #262626" > modify function drop create alter error, stored procedure also has the same problem, here do not know whether there is a direct modification of the method I have not found, welcome to Exchange
How to create a function with MySQL