Oracle中没有时间的日期类型

问题描述 投票:17回答:2

在Oracle 10g中,我在表中使用DATE类型时出现问题。我只想要我的DATE现场商店只有DATE没有时间自动。

有这么多的解决方案,我知道它就像使用TO_CHARTO_DATETRUNC但我面临着我使用如此多的程序来插入或更新数据并且没有时间更新所有这些。

我怎么能解决这个问题?

oracle datetime date oracle10g
2个回答
27
投票

最好的解决方案是:

  1. 从DATE列中删除所有时间(update yourtable set yourdatecolumn = trunc(yourdatecolumn)
  2. 通过使用check (yourdatecolumn = trunc(yourdatecolumn))在列上放置检查约束,确保所有未来日期都不包含时间部分
  3. 调整所有INSERT和UPDATE语句,或者 - 如果你很幸运 - 调整你的API,只插入TRUNCed日期。

最简单的解决方案是:

  1. (可选)从DATE列中删除所有时间。
  2. 创建设置:new.yourdatecolumn := trunc(:new.yourdatecolumn);的前行插入或更新数据库触发器

-4
投票

我这样用

插入:Insert into table (name_date) values(to_date(current_date,'dd/mm/yyyy'));更新:update table set name_date=to_date(current_date,'dd/mm/yyyy') where id=1;

就这样...

© www.soinside.com 2019 - 2024. All rights reserved.