In Oracle, TO_CHAR function can convert a numeric value to string using the specified format. In MariaDB, you can use FORMAT function as well as other string functions and expressions.
Oracle:
-- Convert the price to string format SELECT TO_CHAR(1000, 'FM$9,999,999') FROM dual; # $1,000
MariaDB:
-- Convert the price to string format SELECT CONCAT('$', FORMAT(1000, 0)); # $1,000
Typical conversion examples:
Oracle | MariaDB | |
1 | TO_CHAR(1000) | CAST(1000 AS CHAR) |
2 | TO_CHAR(1000, 'FM$9,999,999') | CONCAT('$', FORMAT(1000, 0)) |
3 | TO_CHAR(1000, '9,999,999') | FORMAT(1000, 0) |
4 | TO_CHAR(123456, '999,999.9') | FORMAT(123456, 1) |
5 | TO_CHAR(123456.123, '999,999.9') | FORMAT(123456.123, 1) |
Adding leading zeros:
Oracle | MariaDB | Outout | |
1 | TO_CHAR(15, 'FM099') | LPAD(FORMAT(15, 0), 3, '0') | 015 |
For more information, see Oracle to MariaDB Migration.