Wednesday, February 9, 2011

Oracle DB: difference between date and timestamp

http://www.databasejournal.com/features/oracle/article.php/2234501/A-Comparison-of-Oracles-DATE-and-TIMESTAMP-Datatypes.htm

basically: use DATE in "normal" cases, and TIMESTAMP when computing time intervals is important.

in SQLDeveloper:

create table TESTDATES (
column1 date,
column2 timestamp(6)
)

first do this to display dates in all their splendor:

alter session set NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS';



If you use the JPA wizard in Eclipse, you will find that DATE is mapped to a java.util.Date (with a @Temporal annotation), while TIMESTAMP is mapped to a java.sql.Timestamp

@Temporal( TemporalType.DATE)
private Date column1;

private Timestamp column2;

No comments: