金仓数据库兼容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$;
本文介绍了金仓数据库新版本中添加的sys.year函数,该函数兼容MySQL的year函数语法,用于从文本提取并处理日期的年份部分。函数使用plpgsql语言编写,可根据给定的timestamp或文本计算年份值。
1万+

被折叠的 条评论
为什么被折叠?



