C/C++教程

oracle函数trunc()用法

本文主要是介绍oracle函数trunc()用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

trunc() 截取日期或者数字

参考链接:https://www.cnblogs.com/xiaoyudz/archive/2011/03/18/1988467.html
官方注释:

Syntax
TRUNC(date [, fmt ]) 
Purpose
The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. The value returned is always of datatype DATE, even if you specify a different datetime datatype for date. If you omit fmt, then date is truncated to the nearest day. Please refer to "ROUND and TRUNC Date Functions" for the permitted format models to use in fmt.

Examples
The following example truncates a date:
SELECT TRUNC(TO_DATE('27-OCT-92','DD-MON-YY'), 'YEAR')
  "New Year" FROM DUAL;
 
New Year
---------
01-JAN-92 

日期

-- 2020-01-01
select trunc(TO_DATE('2020-11-08', 'YYYY-MM-DD'),'YYYY') from dual;

数字

-- 默认精度为0,结果为123
select trunc(123.456) from dual;
-- 123.45 采用的是去尾法
select trunc(123.456, 2) from dual;
-- 120
select trunc(123.456, -1) from dual;;
-- 100
select trunc(123.456, -2) from dual;
-- 0
select trunc(123.456, -3) from dual;
这篇关于oracle函数trunc()用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!