Type conversion functions convert one data type to another. For example, converting between numbers, time, and strings.
Example: Converting time strings to the date and time data types
In an Oracle tenant, you can use the TO_DATE function to convert strings to the date and time data types. The second argument in the TO_DATE function specifies a date format, which must conform to the system date format. SQL statement:
SELECT to_date('Feb 20, 2020', 'Mon dd, YYYY') t1
, to_date('18:30:45', 'HH24:MI:SS') t2
, to_date('2020/11/11 00:30:00', 'YYYY/MM/DD HH24:MI:SS') t3
FROM dual \G
*************************** 1. row ***************************
T1: 2020-02-20 00:00:00
T2: 2020-03-01 18:30:45
T3: 2020-11-11 00:30:00
1 row in set (0.00 sec)
In an Oracle tenant, you can use the TO_CHAR function to convert date and time data types to strings.
Example: Converting between numbers and strings
In an Oracle tenant, you can use the TO_CHAR function to convert numbers to strings. You can use the TO_NUMBER function to convert strings to numbers.
SELECT to_number('3.14') n1, to_number('-3.14') n2, to_char(3.14159,'99.99') c1
FROM DUAL;
+------+-------+--------+
| N1 | N2 | C1 |
+------+-------+--------+
| 3.14 | -3.14 | 3.14 |
+------+-------+--------+
1 row in set (0.01 sec)