compatibility Query for to_number()

mysql, oracle

Solution

Create a custom function in your mysql db with name `to_number` which takes same parameter and returns integer . You can then use `cast` function inside your custom function

` DELIMITER $$` `DROP FUNCTION IF EXISTS to_number$$` `CREATE FUNCTION to_number (number VARCHAR(10)) RETURNS INT (11)` `BEGIN` `RETURN (CAST(number AS SIGNED));` `END$$` `DELIMITER ;` This will create a custom/userdefined function with to_number as name Then you can use your query both in oracle and mysql

Problem

In this query using `to_number()` in oracle. How to write compatibility query for oracle and mysql databases. ``` SELECT col1 FROM table WHERE condition ORDER BY TO_NUMBER(col2); ``` Here `col2` is `varchar2` datatype. Suppose i was used `ORDER BY` command in this query must use converting function i.e `to_number(col2)`,this function not available in mysql.so please give correct solution for above problem

Original source