Portable way to add dates between Oracle and MySQL?
-
03-07-2021 - |
質問
Is there any way to add dates/times that will be portable between Oracle and MySQL?
For example, in Oracle, adding col + 1
to a date column will add a day.
In MySQL, adding col + 1
to a datetime
column will add a SECOND.
Is there a function that would give the same results in both?
(I'm trying to use this in an order by
, for example, order by col1 + col2/(60*24)
- if it were part of the SELECT or WHERE, there might be better options.)
Thanks!
他のヒント
If you're looking to create an app that will work on oracle and MySQL using the same set of queries, did you consider shipping a script with it that will create stored procedures to do the minor work you require e.g. creating a DATE_ADD_DAYS procedure that you then call. The sproc contains the db specific stuff and your app contains only calls to these sprocs you know will exist (because they're in your install script)