Cast and Convert Functions

Cast and convert functions transform data between different types.

Cast and convert functions include:
  • TO_DATE'(' value_returned_expression [, format_mask] ')' : Converts a string to a date using the specified format_mask.

    Inputs: A string (VARCHAR2) and an optional format mask.

    Example:
    TO_DATE('2024-01-03','yyyy-MM-dd')
  • TO_TIMESTAMP'(' value_returned_expression [, format_mask] ')' : Converts a string to a timestamp using the specified format_mask.

    Inputs: A string (VARCHAR2) and an optional format mask.

    Example:
    TO_TIMESTAMP('2024-01-03 01:01:01','yyyy-MM-dd HH:mm:ss')
  • CAST'(' value_returned_expression AS data_type ')' : Converts the expression to the specified data type.

    Inputs: Any compatible data types.

    Example:
    CAST(CUSTOMERS.CUST_YEAR_OF_BIRTH AS VARCHAR2(20))
    The following table shows the CAST compatibility between six datatypes: VARCHAR2, NUMBER, BIGDECIMAL, LARGEINT, DATE, and TIMESTAMP. The table cells indicate whether the CAST between the source and target datatypes is allowed (Yes) or not (No).
    Source/Target VARCHAR2 NUMBER BIGDECIMAL LARGEINT DATE TIMESTAMP
    VARCHAR2 Yes Yes Yes Yes Yes Yes
    NUMBER Yes Yes Yes Yes No No
    BIGDECIMAL Yes Yes Yes Yes No No
    LARGEINT Yes Yes Yes Yes No No
    DATE Yes No No No Yes Yes
    TIMESTAMP Yes No No No Yes Yes
  • INT'(' value_returned_expression ')' : Converts an expression to an integer..

    Inputs: Exact numeric types. Example: NUMBER, LARGEINT, DOUBLE, BIGDECIMAL.

    Example:
    INT('12.12') // function output will be 12
  • BIGINT'(' value_returned_expression ')' : Converts an expression to a large integer.

    Inputs: Exact numeric types. Example: NUMBER, LARGEINT, DOUBLE, BIGDECIMAL.

    Example:
    BIGINT('1234567890.1234567890') // function output will be 1234567890