Patrik Mihalčin
Patrik Mihalčin

Reputation: 3971

SQL datatype for java.time.Duration

I have following JPA entity:

@Entity
public class Notification {

    private Duration deliveryTimeLimit;

    public Duration getDeliveryTimeLimit() {
        return deliveryTimeLimit;
    }

    public void setDeliveryTimeLimit(Duration deliveryTimeLimit) {
        this.deliveryTimeLimit = deliveryTimeLimit;
    }

}   

I'd like to store Duration to database.

What datatype should I use in Oracle database?

When I choose NUMBER, then I have to specify 1 minute as 60000000000 nanoseconds while loading data from csv file.

Upvotes: 0

Views: 813

Answers (1)

loic
loic

Reputation: 151

INTERVAL DAY TO SECOND data type is your friend here. See: How to represent Oracle Interval in Java

Additionaly, you may check Oracle database data type: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Data-Types.html#GUID-F8686599-B7AE-477D-8A58-FA0AA8B2C348

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select interval '1' minute from dual;

INTERVAL'1'MINUTE
---------------------------------------------------------------------------
+00 00:01:00

Upvotes: 2

Related Questions