首页 > 编程知识 正文

mysql date trunc用法Oracle数据库trunc函数的用法,oracle中listagg函数的用法

时间:2023-05-05 07:57:07 阅读:260852 作者:2131

trunc 函数可用于截取日期时间

用法:trunc(字段名,精度)

具体实例:

在表table1中,有一个字段名为sysdate,该行id=123,日期显示:2016/10/28 15:11:58

1、截取时间到年时,sql语句如下:

select trunc(sysdate,'yyyy') from table1 where id=123;  --yyyy也可用year替换

显示:2016/1/1

2、截取时间到月时,sql语句:

select trunc(sysdate,'mm') from table1 where id=123;

显示:2016/10/1

3、截取时间到日时,sql语句:

select trunc(sysdate,'dd') from table1 where id=123;

显示:2016/10/28

4、截取时间到小时时,sql语句:

select trunc(sysdate,'hh') from table1 where id=123;

显示:2016/10/28 15:00:00

5、截取时间到分钟时,sql语句:

select trunc(sysdate,'mi') from table1 where id=123;

显示:2016/10/28 15:11:00

6、截取时间到秒暂时不知道怎么操作

7、不可直接用trunc(sysdate,'yyyy-mm-dd'),会提示“精度说明符过多”

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。