在Oracle 10g中,我在表中使用DATE
类型时出现问题。我只想要我的DATE
现场商店只有DATE
没有时间自动。
有这么多的解决方案,我知道它就像使用TO_CHAR
和TO_DATE
或TRUNC
但我面临着我使用如此多的程序来插入或更新数据并且没有时间更新所有这些。
我怎么能解决这个问题?
最好的解决方案是:
update yourtable set yourdatecolumn = trunc(yourdatecolumn)
)check (yourdatecolumn = trunc(yourdatecolumn))
在列上放置检查约束,确保所有未来日期都不包含时间部分最简单的解决方案是:
:new.yourdatecolumn := trunc(:new.yourdatecolumn);
的前行插入或更新数据库触发器我这样用
插入: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;
就这样...