I am trying to create a custom function using the SELECT query result in MySQL.
Below is a sample custom function which am trying to achieve. When I execute this script, it throws SQL error on set statement. Please advise how this can be done.
My attempt is below:
DELIMITER //
CREATE FUNCTION get_max(
salary INT
)
RETURNS INT
BEGIN
DECLARE max_salary INT;
SET max_salary = select MAX(salary) from employee; --statement to check
RETURN max_salary;
END; //
DELIMETER;
There are few concerns in your function -
So, The correct syntax should be -
DELIMITER //
CREATE FUNCTION get_max()
RETURNS INT
BEGIN
DECLARE max_salary INT;
SELECT MAX(salary)
INTO max_salary
FROM employee;
RETURN max_salary;
END;
//
DELIMETER;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.