[20170414]round(sysdate,'day').txt

简介: [20170414]round(sysdate,'day').txt http://www.itpub.net/thread-2086507-1-1.html SCOTT@book> @ &r/ver1 PORT_STRING                  ...

[20170414]round(sysdate,'day').txt

http://www.itpub.net/thread-2086507-1-1.html

SCOTT@book> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> select sysdate S1, round(sysdate) S2 , round(sysdate,'day') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-14 16:15:09 2017-04-15 00:00:00 2017-04-16 00:00:00

SCOTT@book> select sysdate-8/24 S1, round(sysdate-8/24) S2 , round(sysdate-8/24,'day') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-14 08:15:37 2017-04-14 00:00:00 2017-04-16 00:00:00

SCOTT@book> select sysdate-8/24 S1, round(sysdate-8/24) S2 , round(sysdate-8/24,'hh') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-14 08:20:55 2017-04-14 00:00:00 2017-04-14 08:00:00

SCOTT@book> select sysdate S1, round(sysdate) S2 , round(sysdate,'hh24') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-14 16:21:10 2017-04-15 00:00:00 2017-04-14 16:00:00

SCOTT@book> select sysdate S1, round(sysdate) S2 , round(sysdate,'hh24') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-14 16:34:50 2017-04-15 00:00:00 2017-04-14 17:00:00

--//自己开始也感觉很奇怪,round(sysdate,'day') 中 day表示天,这样向上,向下取最多是2017-04-15 00:00:00,而不会是2017-04-16 00:00:00
--//而我取时间又是正确的。你可以发现这个采用类似四舍五入的算法。

--//仔细看官方文档:
http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions242.htm#SQLRF52037
格式      表示
--------- ---------
DDD DD J  day
DAY DY D  Starting day of the week

-- DAY 表示 Starting day of the week。

SCOTT@book> select sysdate-2 S1, round(sysdate-2) S2 , round(sysdate-2,'day') DAY from dual;
S1                  S2                  DAY
------------------- ------------------- -------------------
2017-04-12 16:38:26 2017-04-13 00:00:00 2017-04-16 00:00:00

--//看来以后看文档要仔细一些。我个人建议使用trunc,估计很少人使用round。

目录
相关文章
|
6天前
DATE_FORMAT函数使用
DATE_FORMAT函数使用
179 0
|
11月前
|
数据库
Data truncation: Incorrect date value: ‘2022-11-28T16:00:00.000Z‘ for column ‘start_date‘ at row 1
Data truncation: Incorrect date value: ‘2022-11-28T16:00:00.000Z‘ for column ‘start_date‘ at row 1
189 0
|
11月前
|
OceanBase
to_date 和 sysdate
to_date 和 sysdate
496 0
|
12月前
|
SQL 关系型数据库
Postgre SQL date_trunc() 和timestamp
Postgre SQL date_trunc() 和timestamp
87 0
|
API
can't convert BigInt value to Number value
can't convert BigInt value to Number value
183 0
|
SQL Oracle 关系型数据库
[20180310]12c exp 无法dirct的情况.txt
[20180310]12c exp 无法dirct的情况.txt --//前一阵子测试.exp 无法dirct的情况的链接: http://blog.itpub.net/267265/viewspace-2151290/ --//12c 改进增加字段与缺省值的情况,允许不要加not null修改表块.
1442 0
|
SQL Oracle 关系型数据库
[20180226]exp 无法dirct的情况.txt
[20180226]exp 无法dirct的情况.txt http://blog.csdn.net/leshami/article/details/9146023 传统路径导出 VS 直接路径导出(oracle exp direct=y) 1、两者的差异 a、 Conventional path Export     传统路径模式使用SQL SELECT语句抽取表数据。
1200 0
|
Oracle 关系型数据库 数据库
[20171127]dual.txt
[20171127]dual.txt --//我曾经提到如果在nomount,mount阶段,desc dual,启动到open阶段时,数据库会直接崩溃. --//链接:http://blog.
809 0
|
Oracle 关系型数据库 Linux
[20170918]NLS_DATE_FORMAT设置.txt
[20170918]NLS_DATE_FORMAT设置.txt --//昨天看了链接www.cnblogs.com/kerrycode/p/7518890.html,里面提到 注意:环境变量NLS_DATE_FORMAT必须和NLS_LANG一起设置,否则不会生效(这个才是总结这篇文章的初衷,以前一直没有注意这个问题 )。
1396 0
|
SQL 索引 Windows
[20150904]exp slow.txt
[20150904]exp slow.txt --昨天看一个贴子,链接如下: http://www.itpub.net/thread-1936560-1-1.
865 0