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

发布时间:2021-12-28 17:58:35 作者:小新
来源:亿速云 阅读:190

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

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;

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

推荐阅读:
  1. Oracle函数获取IDCARD中年龄
  2. 根据日期计算年龄

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

大数据 函数

上一篇:Apache DolphinScheduler高危漏洞CVE-2020-11974及CVE-2020-13922的实例分析

下一篇:Contact Form 7插件中的不受限制文件上传漏洞CVE-2020-35489该怎么分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》