Date type without time in Oracle

后端 未结 2 2009
南方客
南方客 2020-12-10 11:39

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.<

相关标签:
2条回答
  • 2020-12-10 11:58

    The best solution would be to:

    1. remove all times from your DATE column (update yourtable set yourdatecolumn = trunc(yourdatecolumn))

    2. ensure that all future dates contain no time part by placing a check constraint on the column by using check (yourdatecolumn = trunc(yourdatecolumn))

    3. 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. (Optionally) remove all times from your DATE column.

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

    0 讨论(0)
  • 2020-12-10 12:16

    i use like this

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

    that's all...

    0 讨论(0)
提交回复
热议问题