方法一:利用months_between 函数计算

SELECT TRUNC(months_between(sysdate, birthday)/12) AS age
from dual;

方法二:日期转换为 'yyyyMMdd' 格式后,相差一年的两个日期差为:10000,缺点是只能精确到年,并且不能四舍五入。
select TRUNC((to_char(sysdate, 'yyyyMMdd') - to_char(birth, 'yyyyMMdd')) /
10000) as age
from mytable

/**************TRUNC之日期********************/

select trunc(sysdate) from dual ;--2011-3-18 今天的日期为2011-3-18
select trunc(sysdate, 'mm') from dual ; --2011-3-1 返回当月第一天.
select trunc(sysdate,'yy') from dual; --2011-1-1 返回当年第一天
select trunc(sysdate,'dd') from dual; --2011-3-18 返回当前年月日
select trunc(sysdate,'yyyy') from dual; --2011-1-1 返回当年第一天
select add_months(to_date('2018-01-01','yyyy-mm-dd'),12)-1 from dual; -- 2018-12-31 返回当年第一天
select trunc(sysdate,'d') from dual ; --2011-3-13 (星期天)返回当前星期的第一天
select trunc(sysdate, 'hh') from dual ; --2011-3-18 14:00:00 当前时间为14:41
select trunc(sysdate, 'mi') from dual ; --2011-3-18 14:41:00 TRUNC()函数没有秒的精确
SELECT to_date('20180818','yyyymmdd')-to_date('20180727','yyyymmdd') FROM dual;

/***************TRUNC之数字********************/
/*
TRUNC(number,num_digits)
Number 需要截尾取整的数字。
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
select trunc(123.458) from dual; --123
select trunc(123.458,0) from dual ;--123
select trunc(123.458,1) from dual ;--123.4
select trunc(123.458,-1) from dual; --120
select trunc(123.458,-4) from dual; --0
select trunc(123.458,4) from dual ;--123.458
select trunc(123) from dual ;--123
select trunc(123,1) from dual ;--123
select trunc(123,-1) from dual ;--120

oracle笔记之计算年龄、工龄和TRUNC的更多相关文章

  1. oracle 根据出生日期计算年龄的年月日

    select years,months,abs( trunc( newer_date- add_months( older_date,years*12+months ) ) ) days from ( ...

  2. Oracle 通过出生日期计算年龄

    方法一: SELECT TRUNC(months_between(sysdate, birth)/12) AS age from mytable 方法二: select TRUNC((to_char( ...

  3. oracle根据身份证号码 计算年龄、性别

    一.Oracle根据身份证判断性别: 女生身份证: 431382198103246985 男生身份证: 150921197208173492 SQL语句如下:   select decode(mod ...

  4. 问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题

    SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,birthday)/12,1) FROM ltteacherinfo where name='朱雪东111'这个报错ORA 00 ...

  5. 韩顺平Oracle笔记

    韩顺平Oracle笔记 分类: DataBase2011-09-07 10:24 3009人阅读 评论(0) 收藏 举报 oracle数据库sqljdbcsystemstring   目录(?)[-] ...

  6. Oracle笔记 多表查询

    Oracle笔记  多表查询   本次预计讲解的知识点 1. 多表查询的操作.限制.笛卡尔积的问题: 2. 统计函数及分组统计的操作: 3. 子查询的操作,并且结合限定查询.数据排序.多表查询.统计查 ...

  7. Oracle时间日期计算--计算某一日期为一年中的第几周

    Oracle时间日期计算--计算某一日期为一年中的第几周 select to_char(sysdate-10,'yyyymmdd')||':iw:'||to_char(sysdate-10,'iw') ...

  8. 虚拟机VMWARE上ORACLE License 的计算

    Oracle License的计算有两种方式:按照用户数和CPU个数. 其中按CPU计算方式如下: License Number = The Number of CPU Cores  *  Core ...

  9. Oracle笔记 目录索引

    Oracle笔记 一.oracle的安装.sqlplus的使用 Oracle笔记 二.常用dba命令行 Oracle笔记 三.function .select Oracle笔记 四.增删改.事务 Or ...

随机推荐

  1. C前序遍历二叉树Morris Traversal算法

    首先来递归算法,简单易懂: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef ...

  2. CRM 线索 客户 统称为 资源 客户服务管理篇 销售易

    线索 客户 统称为 资源 - 国内版 Binghttps://cn.bing.com/search?FORM=U227DF&PC=U227&q=%E7%BA%BF%E7%B4%A2+% ...

  3. PHP 对象继承

    对象继承 继承已为大家所熟知的一个程序设计特性,PHP 的对象模型也使用了继承.继承将会影响到类与类,对象与对象之间的关系. 比如,当扩展一个类,子类就会继承父类所有公有的和受保护的方法.除非子类覆盖 ...

  4. [原]Arcgis arcmap修改图元配色

    感谢南师大的“深爱”提供的帮助 1.选择识别工具,点击海洋,确定海洋色块的color index为255 2.右键tif选择属性 3.选择分页栏中的符号化(Symbology) 4.找到对应的Labe ...

  5. fkutter Stepper步骤指示器

    一个Material Design 步骤指示器,显示一系列步骤的过程 import 'package:flutter/material.dart'; class StepperDemo extends ...

  6. openresty开发系列4--nginx的配置文件说明

    openresty开发系列4--nginx的配置文件说明 Nginx基本配置 Nginx的主配置文件是:nginx.conf,nginx.conf主要组成如下: # 全局区   有一个工作子进程,一般 ...

  7. "AttributeError: /lib64/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup"

    以前在openssl,有 EVP_CIPHER_CTX_cleanup函数. 1.1.0版本中 替换成为EVP_CIPHER_CTX_reset 解决办法: 找到报错的文件vim /usr/local ...

  8. Text Prompted Remote Speaker Authentication : Joint Speech and Speaker Recognition/Verification System :: Major Project ::: Introduction

    转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2010/12/text-prompted-remote-speaker.html Biometrics ...

  9. google浏览器插件开发教程

    谷歌插件开发之notifications通知API全解析https://blog.csdn.net/WU5229485/article/details/82012167浏览器API大全https:// ...

  10. Swift4.0复习类型定义、类型投射等操作

    1.类型定义: /// 这里将MyInt定义为Int32类型 typealias MyInt = Int32   /// 这里将MyArrayInt定义为[MyInt]数组类型 typealias M ...