Custom function for DDL operation example of MySQL database
This article mainly introduces the custom function of the MySQL database DDL operation example, the content of the article is carefully selected and edited by the author, it has a certain pertinence, and it is of great significance to everyone's reference, the following is to understand the custom function of the MySQL database DDL operation example with the author.
1. Background
* Custom functions are very similar to stored procedures, but must have a return value.
two。 Custom function example [factorial]
* create a custom function func_factorial
Delimiter sets statement Terminator
Mysql > delimiter / / mysql > CREATE FUNCTION func_factorial (total INT)-> RETURNS INT-> BEGIN-> DECLARE i INT;-> DECLARE res INT;-> SET I = 1;-> SET res = 1;-> IF total SET total = 1;-> END IF;-> WHILE i SET res = res * I;-> SET I = I + 1 -> END WHILE;-> RETURN res;-> END; / / Query OK, 0 rows affected (0.01 sec) mysql > delimiter
* call the custom function func_factorial
Mysql > SELECT func_factorial (10); +-+ | func_factorial (10) | +-+ | 3628800 | +-+ 1 row in set (0.01sec)
3. Summary
In order to demand-driven technology, there is no difference in technology itself, only in business.
After reading the above custom functions about MySQL database DDL operation examples, many readers must have some understanding. If you need more industry knowledge and information, you can continue to follow our industry information column.