Skip to content

Latest commit

 

History

History
107 lines (77 loc) · 2.93 KB

File metadata and controls

107 lines (77 loc) · 2.93 KB
description
Converts the input expression to a character/string using the specified format.

TO_CHAR

Syntax

TO_CHAR(expression time, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(CAST('01:02:03' AS TIME) , 'HH:MI');
-- 01:02

{% endcode %}

TO_CHAR(expression date, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(CAST('2021-02-11' AS DATE) , 'yyyy.mm.dd');
-- 2021.02.11

{% endcode %}

TO_CHAR(expression int32, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(10, '#')
-- 10

{% endcode %}

TO_CHAR(expression float, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(7.5, '#.#')
-- 7.5

{% endcode %}

TO_CHAR(expression int64, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(10, '#')
-- 10

{% endcode %}

TO_CHAR(expression double, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(7.5, '#.#')
-- 7.5

{% endcode %}

TO_CHAR(expression timestamp, format varchar) → varchar

  • expression: Expression to convert to a string.
  • format: Format to use for the conversion.

Examples

{% code title="TO_CHAR example" %}

SELECT TO_CHAR(CAST('2013-04-05 01:02:03' AS TIMESTAMP) , 'mm/dd/yyyy, hh:mi');
-- 04/05/2013, 01:02

{% endcode %}