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

TO_CHAR

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

The TO_CHAR() function converts a value to a string value using a vendor-specific format mask.

SELECT to_char(date '2000-01-01, 'YYYY/MM/DD');
create.select(toChar(Date.valueOf("2000-01-01"), "YYYY/MM/DD")).fetch();

The result being

+------------+
| to_char    |
+------------+
| 2000/01/01 |
+------------+

Dialect support

This example using jOOQ:

toChar(Date.valueOf("2000-01-01"), "YYYY/MM/DD")

Translates to the following dialect specific expressions:

-- ACCESS
cstr(#2000/01/01#)

-- ASE, SQLITE, SYBASE
CAST('2000-01-01' AS varchar)

-- AURORA_MYSQL, MEMSQL, MYSQL
CAST({d '2000-01-01'} AS char)

-- AURORA_POSTGRES, H2, ORACLE, POSTGRES, REDSHIFT
to_char(DATE '2000-01-01', 'YYYY/MM/DD')

-- BIGQUERY, COCKROACHDB
CAST(DATE '2000-01-01' AS string)

-- CUBRID, HANA, IGNITE, INGRES, SNOWFLAKE, VERTICA
CAST(DATE '2000-01-01' AS varchar)

-- DB2, HSQLDB
CAST(DATE '2000-01-01' AS varchar(32672))

-- DERBY
CAST(DATE('2000-01-01') AS varchar(32672))

-- EXASOL
CAST(DATE '2000-01-01' AS varchar(2000000))

-- FIREBIRD
CAST(DATE '2000-01-01' AS varchar(4000))

-- INFORMIX
CAST(DATETIME(2000-01-01) YEAR TO DAY AS lvarchar)

-- MARIADB
CAST(DATE '2000-01-01' AS char)

-- SQLDATAWAREHOUSE
CAST(CAST('2000-01-01' AS date) AS varchar(8000))

-- SQLSERVER
CAST(CAST('2000-01-01' AS date) AS varchar(max))

-- TERADATA
CAST(DATE '2000-01-01' AS varchar(32000))

(These are currently generated with jOOQ 3.15, see #10141), or translate your own on our website

Feedback

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

The jOOQ Logo