SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE tbl_employees ( emp_id INT AUTO_INCREMENT PRIMARY KEY, emp_name VARCHAR(50), emp_departmentid INT, emp_salary DECIMAL(10, 2) ); INSERT INTO tbl_employees(emp_name, emp_departmentid, emp_salary) VALUES ('Nicole', 2, 1421.42), ('Michael', 3, 4262.53), ('Vince', 1, 6314.96), ('Kobe', 2, 8361.21), ('Bryan', 3, 3626.64), ('Loki', 1, 1332.12), ('Tomo', 3, 12242.88), ('Vilma', 3, 6327.24), ('Petra', 1, 4829.84); DROP FUNCTION IF EXISTS fn_getMaxSalary; -- Create the Function DELIMITER $$ CREATE FUNCTION fn_getMaxSalary() RETURNS DECIMAL(10,2) BEGIN DECLARE _maxSVal DECIMAL(12,4); SELECT MAX(emp_salary) INTO _maxSVal FROM tbl_employees; RETURN _maxSVal; END $$ DELIMITER ; -- EXECUTE SELECT fn_getMaxSalary();

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear