Difference in days between 2 dates Oracle SQL

后端 未结 2 1202
我寻月下人不归
我寻月下人不归 2021-01-28 21:04

Alright, so I\'ve checked many many many other posts on stackoverflow to see if this is mentioned anywhere, and the answers provided don\'t quite make sense to me...I\'m thinkin

2条回答
  •  借酒劲吻你
    2021-01-28 22:02

    The easeyest way of doing this is writing a function in oracle like DATEDIFF in mysql, id done this like :

    function        datediff( p_what in varchar2, p_d1 in date, p_d2 in date) return number as  l_result    number; 
    BEGIN
          select (p_d2-p_d1) * 
                 decode( upper(p_what), 'SS', 24*60*60, 'MI', 24*60, 'HH', 24, NULL ) 
           into l_result from dual; 
    
          return l_result; 
    
    END;
    

    and call this function like :

    DATEDIFF('YYYY-MM-DD', SYSTIMESTAMP, SYSTIMESTAMP)
    

    in your sql command

提交回复
热议问题