DROP FUNCTION
IF EXISTS getAge;
CREATE FUNCTION getAge (idcard VARCHAR) RETURNS INT
BEGIN
DECLARE
age INT;
SET age = 0;
SELECT
YEAR (curdate()) -
IF (
length(idcard) = 18,
substring(idcard, 7, 4),
IF (
length(idcard) = 15,
concat('19', substring(idcard, 7, 2)),
NULL
)
) INTO age
FROM
DUAL;
RETURN age;
END;
执行报错
[SQL]DROP FUNCTION
IF EXISTS getAge;
受影响的行: 0
时间: 0.095s
[SQL]
CREATE FUNCTION getAge (idcard VARCHAR) RETURNS INT
BEGIN
DECLARE
age INT;
SET age = 0;
SELECT
YEAR (curdate()) -
IF (
length(idcard) = 18,
substring(idcard, 7, 4),
IF (
length(idcard) = 15,
concat('19', substring(idcard, 7, 2)),
NULL
)
) INTO age
FROM
DUAL;
RETURN age;
END;
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') RETURNS INT
BEGIN
DECLARE
age INT;
SET age = 0;
SELECT
YEAR (c' at line 1