在Oracle中插入日期值 [英] Inserting date value in oracle
本文介绍了在Oracle中插入日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Oracle表中插入没有时间的日期值,以便按日期排序.
在此先感谢
Asok
How to insert a date value without time into oracle table so as to sort by date.
Thanks in advance
Asok
推荐答案
没有仅日期数据类型.
您可以将其插入为
There is no Date only data type.
You can insert it as
Insert into yourtable values(to_date('05/09/2011','dd/mm/yyyy'));
或者您可以选择为
or you can select as
Select to_char(yourdate, 'dd/mm/yyyy') from yourtable;
如果要将时间部分设置为午夜,可以使用TRUNC.例如,要在午夜添加当前日期:
When inserting the data if you want to set time portion to midnight, you can use TRUNC. For example, to add current date at midnight:
INSERT INTO TableName (DateColumnName) VALUES (TRUNC(SYSDATE));
正如Prerak所指出的那样,您在选择数据时也可以处理时间部分.例如:
As Prerak also pointed out you can handle the time portion also when selecting the data. For example:
SELECT TRUNC(DateColumnName)
FROM TableName
WHERE TRUNC(DateColumnName) < SYSDATE
这篇关于在Oracle中插入日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文