Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle calculates the function of time span

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Displays the span from the current time

-- calculate the time span: the return value is X days, y and z minutes.

Declare

Ln_day_count number (10)

Ln_hour_count number (10)

Ln_min_count number (10)

Ls_time_sent_last varchar2 (20): = '2015-06-07 0815 0440 20'

Ls_timespan varchar2: =''

Begin

-calculate the number of days

Select floor (sysdate-To_date (ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss')) into ln_day_count FROM dual

If ln_day_count! = 0 then

Ls_timespan: = to_char (ln_day_count) | | 'days'

Dbms_output.put_line (ls_timespan)

End if

-calculate the number of hours

Select mod (floor (sysdate-To_date (ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss') * 24), 24) into ln_hour_count FROM dual

If ln_hour_count! = 0 then

Ls_timespan: = ls_timespan | | to_char (ln_hour_count) | | 'when'

Dbms_output.put_line (ls_timespan)

End if

-- calculate minutes

Select mod (mod (floor (sysdate-To_date (ls_time_sent_last, 'yyyy-mm-dd hh34-mi-ss') * 24060), 24060), 60) into ln_min_count FROM dual

If ln_min_count! = 0 then

Ls_timespan: = ls_timespan | | to_char (ln_min_count) | | 'points'

Dbms_output.put_line (ls_timespan)

End if

End

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report