金仓数据库兼容mysql year函数语法如下,同时新版本自带year函数:
CREATE OR REPLACE FUNCTION sys.year(text)
RETURNS double precision
LANGUAGE plpgsql
AS $function$
declare
year_result float8;
begin
if $1 is not null then
year_result = date_part('year', $1 :: timestamp);
if year_result is not null then
if year_result >= 1000 and year_result <= 9999 then
return year_result;
else
return null;
end if;
else
return null;
end if;
else
return null;
end if;
end;
$function$;