博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL语句计算周岁
阅读量:6979 次
发布时间:2019-06-27

本文共 671 字,大约阅读时间需要 2 分钟。

计算周岁的SQL语句:

select trunc(months_between(sysdate,date'1992-12-8')/12)  年龄 from dual;

用到两个函数:trunc和months_between

trunc函数两种用法:

1、trunc(number1,number2),只舍不入取值。

number1:原始数据,要操作的对象

number2:操作要求

number2>0,保留到小数点右边第number2位.

number2<0,将小数点左边第number2位舍去。

number2=0或者没有number2参数,是只保留到整数。

例:trunc(5.75698,2),结果:5.75

      trunc(1789.23,-2),结果:1700

      trunc(5.75,0)或者trunc(5.75),结果:5

2、trunc(date,month/year),将date截取到年或者月。

例:trunc(date'2014-7-16','month')  结果:2014/7/1

      trunc(date'2014-7-16','year') 结果:2014/1/1

months_between函数

months_between(x,y),计算x-y,结果是相差的月份数。

例子:months_between(sysdate,date'1996-12-8')  结果:225.824334677419---表示相差的月份数

 

     

转载于:https://www.cnblogs.com/haoxiaopa/p/4852151.html

你可能感兴趣的文章
javascript promise编程
查看>>
python自定义库文件路径
查看>>
spring security之httpSecurity 专题
查看>>
org.springframework.jdbc.datasource
查看>>
HDU 4467 分块
查看>>
slurm用户快速入门手册
查看>>
使用最小堆优化Dijkstra算法
查看>>
选择排序
查看>>
韩顺平_JAVA_视频教程_下载(打开迅雷,直接复制链接地址即可下载)
查看>>
[android] 从gallery获取图片
查看>>
[日常] Go语言圣经-函数递归习题
查看>>
泛型中? super T和? extends T的区别
查看>>
Unity3D心得分享
查看>>
excel增加上一列的数值(日期)
查看>>
Java数据结构一 —— Java Collections API中的表
查看>>
2018-2019-1 20165206 《信息安全系统设计基础》第4周学习总结
查看>>
js canvas游戏初级demo-上下左右移动
查看>>
css3选择器二
查看>>
初学Java——选择
查看>>
转 微博 linux中ctime,mtime,atime的区别
查看>>