mysql function code example
Example 1: mysql create function
DELIMITER $$
CREATE FUNCTION f_employee_count(p_dept_no INTEGER) RETURNS INTEGER
DETERMINISTIC NO SQL READS SQL DATA
BEGIN
DECLARE v_emp_count INTEGER;
SELECT COUNT(*)
INTO v_emp_count
FROM EMPLOYEES E
WHERE E.DEPT_NO = p_dept_no
GROUP BY DEPARTMENT_NO;
RETURN v_emp_count;
END$$
DELIMITER ;
Example 2: mysql some functions
MySQL Miscellaneous Functions
BIT_COUNT
DES_ENCRYPT
DATABASE
DES_DECRYPT
USER
LAST_INSERT_ID
SYSTEM_USER
FORMAT
SESSION_USER
VERSION
CURRENT_USER
CONNECTION_ID
PASSWORD
GET_LOCK
OLD_PASSWORD
RELEASE_LOCK
ENCRYPT
IS_FREE_LOCK
DECODE
BENCHMARK
MD5
INET_NTOA
SHA1
INET_ATON
AES_ENCRYPT
FOUND_ROWS
AES_DECRYPT
STRCMP
Example 3: create function in mysql
CREATE FUNCTION `data-management`.checkTags(tags text)
RETURNS text
DETERMINISTIC
BEGIN
return tags ;
END
SELECT * FROM `data-management`.properties p WHERE `data-management`.checkTags(p.tags = 'tag1,absntee')