DATEDIFF function in Oracle

前端 未结 4 1939
难免孤独
难免孤独 2020-11-30 10:55

I need to use Oracle but DATEDIFF function doesn\'t work in Oracle DB.

How to write the following code in Oracle? I saw some examples using INTERVAL or TRUNC.

4条回答
  •  猫巷女王i
    2020-11-30 11:18

    In Oracle, you can simply subtract two dates and get the difference in days. Also note that unlike SQL Server or MySQL, in Oracle you cannot perform a select statement without a from clause. One way around this is to use the builtin dummy table, dual:

    SELECT TO_DATE('2000-01-02', 'YYYY-MM-DD') -  
           TO_DATE('2000-01-01', 'YYYY-MM-DD') AS DateDiff
    FROM   dual
    

提交回复
热议问题