New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12

DECADE

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Extract the DECADE value from a datetime value.

The DECADE function is a short version of the EXTRACT, passing a DatePart.DECADE value as an argument.

SELECT decade(DATE '2020-02-03');
create.select(decade(Date.valueOf("2020-02-03"))).fetch();

The result being

+--------+
| decade |
+--------+
|    202 |
+--------+

Dialect support

This example using jOOQ:

decade(Date.valueOf("2020-02-03"))

Translates to the following dialect specific expressions:

-- ACCESS
(cdec((datepart('yyyy', #2020/02/03 00:00:00#) / 10)) - ((datepart('yyyy', #2020/02/03 00:00:00#) / 10) < cdec((datepart('yyyy', #2020/02/03 00:00:00#) / 10))))

-- ASE, SYBASE
floor((datepart(yy, '2020-02-03 00:00:00.0') / 10))

-- AURORA_MYSQL, MEMSQL, MYSQL
floor((extract(YEAR FROM {ts '2020-02-03 00:00:00.0'}) / 10))

-- AURORA_POSTGRES, POSTGRES
extract(DECADE FROM TIMESTAMP '2020-02-03 00:00:00.0')

-- COCKROACHDB, FIREBIRD, H2, HANA, HSQLDB, INGRES, MARIADB, ORACLE, REDSHIFT, TERADATA, VERTICA
floor((extract(YEAR FROM TIMESTAMP '2020-02-03 00:00:00.0') / 10))

-- CUBRID
floor((extract(YEAR FROM DATETIME '2020-02-03 00:00:00.0') / 10))

-- DB2
floor((YEAR(TIMESTAMP '2020-02-03 00:00:00.0') / 10))

-- DERBY
floor((YEAR(TIMESTAMP('2020-02-03 00:00:00.0')) / 10))

-- INFORMIX
floor((YEAR(DATETIME(2020-02-03 00:00:00.0) YEAR TO FRACTION) / 10))

-- SQLDATAWAREHOUSE, SQLSERVER
floor((datepart(yy, CAST('2020-02-03 00:00:00.0' AS DATETIME2)) / 10))

-- SQLITE
(CAST((strftime('%Y', '2020-02-03 00:00:00.0') / 10) AS int8) - ((strftime('%Y', '2020-02-03 00:00:00.0') / 10) < CAST((strftime('%Y', '2020-02-03 00:00:00.0') / 10) AS int8)))

(These are currently generated with jOOQ 3.15, see #10141)

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo