189 8069 5689

大数据开发中文年龄函数的示例代码

这篇文章主要介绍大数据开发中文年龄函数的示例代码,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

大渡口网站建设公司创新互联,大渡口网站设计制作,有大型网站制作公司丰富经验。已为大渡口上千余家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的大渡口做网站的公司定做!

create or replace function CHINESEAGE(BirthDate in date, NowDate in date) return string is
      Result string(80); -- 返回值
      MonthCount number(4,0); -- 出生的月份
      DayCount number(6,0); -- 去除月份后的余数(天)
begin
      -- 如果生日大于当前日期,则提示错误
      if BirthDate > NowDate or BirthDate is null or NowDate is null Then
            Result := '不详';
            return(Result);
      end if;

      -- 获取出生多少个月余多少天
      SELECT trunc(Mon), trunc((Mon - trunc(Mon)) * 31)
      INTO MonthCount,DayCount
      FROM (SELECT months_between(NowDate, BirthDate) Mon FROM dual) V;

      -- 如果出生60个月以上,年龄显示为 ##岁
      if MonthCount >= 60 then
            Result := to_char(trunc(MonthCount/12))||'岁';

      -- 如果出生12-59个月,年龄显示为 ##岁##月
      elsif MonthCount >= 12 then
            Result := to_char(trunc(MonthCount/12))||'岁'||to_char(mod(MonthCount,12))||'月';

      -- 如果出生1-11个月,年龄显示为 ##月##天
      elsif MonthCount >= 1 then
            Result := to_char(MonthCount)||'月';
            if DayCount >= 1 then
                  Result := Result || to_char(DayCount) || '天';
            end if;

      -- 如果出生1天-1个月,年龄显示为##天
      elsif DayCount >= 1 then
            Result := to_char(DayCount)||'天';

      -- 如果出生不足1天,年龄显示为1天
      else
            Result := '1天';

      end if;

      return(Result);
end;

以上是“大数据开发中文年龄函数的示例代码”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


分享文章:大数据开发中文年龄函数的示例代码
转载源于:http://cdxtjz.cn/article/jccpeo.html

其他资讯