Oracle中没有时间的日期类型 [英] Date type without time in Oracle

查看:145
本文介绍了Oracle中没有时间的日期类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle 10g中,当我在表中使用 DATE 类型时,我遇到了一个问题。我只是希望我的 DATE 字段存储只有 DATE 没有时间自动。

In Oracle 10g I got a problem when using DATE type in my table. I just want my DATE field store only DATE without time automatically.

有很多解决方案,我知道它就像使用 TO_CHAR TO_DATE TRUNC ,但是我面对的是我使用这么多的程序来插入或更新数据,没有时间更新所有这些。

There's so much solution, I know it like using TO_CHAR and TO_DATE or TRUNC but I faced that I'm using so much procedures to insert or update data and have no time to update all of them.

我可以解决这个问题吗?

How could I resolve this problem?

推荐答案

最好的解决方法是:


  1. 从DATE列中删除所有时间(更新yourtable set yourdatecolumn = trunc(yourdatecolumn)

通过使用 check(yourdatecolumn = trunc(yourdatecolumn))

调整所有INSERT和UPDATE语句,或者 - 如果您幸运 - 调整您的API,只能插入TRUNCed日期。

adjust all your INSERT and UPDATE statements or -if you're lucky- adjust your API, to only insert TRUNCed dates.

最简单的解决方案将是:

The easiest solution would be to:


  1. (可选)从DATE列中删除所有时间。

  1. (Optionally) remove all times from your DATE column.

创建前一行插入或更新数据库触发器,设置:new.yourdatecolumn:= trunc(:new.yourdatecolumn);

Create a before row insert or update database trigger that sets :new.yourdatecolumn := trunc(:new.yourdatecolumn);

这篇关于Oracle中没有时间的日期类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆