DETERMINISTIC
Example
Section titled “Example”CREATE FUNCTION deterministic_example(input INT)RETURNS INTDETERMINISTICBEGIN RETURN input * 2;END;Output
Section titled “Output”Query OK, 0 rows affected (0.01 sec)Explanation
Section titled “Explanation”In the provided example, a function named deterministic_example is created. It accepts an integer input, which it then multiplies by 2. The DETERMINISTIC statement means that MySQL can expect that for the same input, the function will always return the same output. The function is DETERMINISTIC since for any given input, the output (input * 2) will always be the same.
Example
Section titled “Example”CREATE FUNCTION get_sales_tax(total_sales NUMBER)RETURN NUMBER DETERMINISTICISBEGIN RETURN total_sales * 0.09;END;/Output
Section titled “Output”Function GET_SALES_TAX compiledExplanation
Section titled “Explanation”In this example, we create a deterministic function called get_sales_tax that calculates and returns the sales tax. The DETERMINISTIC keyword signifies that the function will always return the same result given the same input.