I have add a column (name updatedAt) in Oracle database table to save updated datetime.
What data type should I choose - Date or Timestamp in oracle?
To create a model/domain class for this table in Java, shall I use java.sql.Timestamp or java.time.Instant for this column. Or is there any other better and recommended data type to use in Java? I am using java 17.
Please suggest data type for both java and oracle to save date and time.
Whichever you want and/or best represents your data.
In Oracle:
DATEis a binary data-type consisting of 7 bytes representing: century, year-of-century, month, day, hour, minute and second. It ALWAYS has all those components.TIMESTAMPis a binary data-type consisting of 7-13 bytes representing: century, year-of-century, month, day, hour, minute, second and 0-6 bytes for fraction seconds depending on the precision of the timestamp.TIMESTAMP WITH TIME ZONEis a binary data-type consisting of 14-20 bytes representing: century, year-of-century, month, day, hour, minute, second, 7 bytes for time-zone information and 0-6 bytes for fraction seconds depending on the precision of the timestamp.Note: None of those data-types store data in any particular human-readable format. The format in which
DATE,TIMESTAMPandTIMESTAMP WITH TIME ZONEdata types are displayed is controlled by the client application which reads from the database.DATEorTIMESTAMP(0)data-types (which you use is personal preference - although there is a slight difference in behaviour if you subtractDATEs you get aNUMBERdata-type representing the difference in days, or fraction of days, and if you subtractTIMESTAMPs you get anINTERVAL DAY TO SECONDdata-type).TIMESTAMP(N)data-type (whereNis the desired number of digits precision for the fractional seconds).TIMESTAMP(N) WITH TIME ZONEdata-type (whereNis the desired number of digits precision for the fractional seconds).