SQL Oracle,使日期时间为其月份的第一天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7850551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle, Make date time's first day of its month
提问by Bilgin K?l??
I have a datevariable, I would like to have convert it to first day of its monh,
我有一个日期变量,我想将其转换为月份的第一天,
- Eg: 10/10/2010 -> 01/10/2010
- Eg: 31/07/2010 -> 01/07/2010
- 例如:10/10/2010 -> 01/10/2010
- 例如:31/07/2010 -> 01/07/2010
回答by MatBailie
According to http://psoug.org/reference/date_func.html, this should work a dandy...
根据http://psoug.org/reference/date_func.html,这应该工作一个花花公子......
SELECT TRUNC(yourDateField, 'MONTH') FROM yourTable
回答by BQ.
SQL> select to_date('31/07/2010', 'DD/MM/YYYY') from dual;
TO_DATE('
---------
31-JUL-10
SQL> select trunc(to_date('31/07/2010', 'DD/MM/YYYY'), 'MM') from dual;
TRUNC(TO_
---------
01-JUL-10
SQL>
回答by schurik
select trunc(sysdate, 'mm') from dual;
回答by Ashish4434
try this one
试试这个
select trunc(sysdate, 'MM')firstday , trunc(last_DAY(sysdate)) lastday from dual;
回答by Erwin Brandstetter
SELECT trunc(to_date('22-AUG-03'), 'MON') FROM dual;
More in the manual.
About Oracle needing a dummy FROM
: Select without a FROM clause in Oracle
手册中有更多内容。
关于 Oracle 需要一个虚拟对象FROM
:在 Oracle 中不使用 FROM 子句进行选择
回答by westman379
Here is a good example:
这是一个很好的例子:
select trunc(to_date('15.11.2019', 'DD.MM.YYYY'), 'MONTH') from dual;